muttakin2301/ccr_train_1000 huggingface dataset:
Code review comment: `"/modules/"` can be replaced with `ProjectConstants.MODULES_ROOT`

Code before review:
private String normalizeFileName(String fileName) {
String orgName = IdentifierUtils.encodeNonFunctionIdentifier(
this.module.packageInstance().packageOrg().toString());
for (Module module : this.module.packageInstance().modules()) {
String sourceRoot;
String packageName;
if (module.isDefaultModule()) {
packageName = IdentifierUtils.encodeNonFunctionIdentifier(
module.packageInstance().packageName().toString());
sourceRoot = module.project().sourceRoot().getFileName().toString();
} else {
packageName = IdentifierUtils.encodeNonFunctionIdentifier(module.descriptor().name().toString());
sourceRoot = module.project().sourceRoot().getFileName().toString() + "/modules/" +
module.moduleName().moduleNamePart();
}
if (fileName.contains(orgName + "/" + packageName + "/")) {
orgName = Pattern.quote(orgName);
packageName = Pattern.quote(packageName);
String normalizedFileName = fileName.replaceAll("^" + orgName + "/" +
packageName + "/.*/", sourceRoot + "/");
normalizedFileName = normalizedFileName.replaceAll("^" + orgName + "/" +
packageName + "/.*", sourceRoot);
return normalizedFileName;
}
}
return fileName;
}

Line under review: sourceRoot = module.project().sourceRoot().getFileName().toString() + "/modules/" +

Code after addressing the review:
private String normalizeFileName(String fileName) {
String orgName = IdentifierUtils.encodeNonFunctionIdentifier(
this.module.packageInstance().packageOrg().toString());
for (Module module : this.module.packageInstance().modules()) {
String packageName = IdentifierUtils.encodeNonFunctionIdentifier(
module.moduleName().toString());
String sourceRoot = module.project().sourceRoot().getFileName().toString();
if (!module.isDefaultModule()) {
sourceRoot = sourceRoot + "/" + ProjectConstants.MODULES_ROOT + "/" +
module.moduleName().moduleNamePart();
}
if (fileName.contains(orgName + "/" + packageName + "/")) {
orgName = Pattern.quote(orgName);
packageName = Pattern.quote(packageName);
String normalizedFileName = fileName.replaceAll("^" + orgName + "/" +
packageName + "/.*/", sourceRoot + "/");
normalizedFileName = normalizedFileName.replaceAll("^" + orgName + "/" +
packageName + "/.*", sourceRoot);
return normalizedFileName;
}
}
return fileName;
}
Code review comment: why remove copyOf?

Code before review:
protected AbstractTreeNode(List<NODE_TYPE> children) {
this.children = children;
}

Line under review: this.children = children;

Code after addressing the review:
protected AbstractTreeNode(List<NODE_TYPE> children) {
this.children = ImmutableList.copyOf(children);
}
Code review comment: The same question about test coverage here?

Code before review:
public void initializeState(FunctionInitializationContext context) throws Exception {
state = context.getOperatorStateStore().getListState(stateDescriptor);
boolean recoveredUserContext = false;
if (context.isRestored()) {
LOG.info("{} - restoring state", name());
for (State<TXN, CONTEXT> operatorState : state.get()) {
userContext = operatorState.getContext();
List<TransactionHolder<TXN>> recoveredTransactions =
operatorState.getPendingCommitTransactions();
List<TXN> handledTransactions = new ArrayList<>(recoveredTransactions.size() + 1);
for (TransactionHolder<TXN> recoveredTransaction : recoveredTransactions) {
recoverAndCommitInternal(recoveredTransaction);
handledTransactions.add(recoveredTransaction.handle);
LOG.info("{} committed recovered transaction {}", name(), recoveredTransaction);
}
{
TXN transaction = operatorState.getPendingTransaction().handle;
if (transaction != null) {
recoverAndAbort(transaction);
handledTransactions.add(transaction);
LOG.info(
"{} aborted recovered transaction {}",
name(),
operatorState.getPendingTransaction());
}
}
if (userContext.isPresent()) {
finishRecoveringContext(handledTransactions);
recoveredUserContext = true;
}
}
}
if (!recoveredUserContext) {
LOG.info("{} - no state to restore", name());
userContext = initializeUserContext();
}
this.pendingCommitTransactions.clear();
currentTransactionHolder = beginTransactionInternal();
LOG.debug("{} - started new transaction '{}'", name(), currentTransactionHolder);
}

Line under review: if (transaction != null) {

Code after addressing the review:
public void initializeState(FunctionInitializationContext context) throws Exception {
state = context.getOperatorStateStore().getListState(stateDescriptor);
boolean recoveredUserContext = false;
if (context.isRestored()) {
LOG.info("{} - restoring state", name());
for (State<TXN, CONTEXT> operatorState : state.get()) {
userContext = operatorState.getContext();
List<TransactionHolder<TXN>> recoveredTransactions =
operatorState.getPendingCommitTransactions();
List<TXN> handledTransactions = new ArrayList<>(recoveredTransactions.size() + 1);
for (TransactionHolder<TXN> recoveredTransaction : recoveredTransactions) {
recoverAndCommitInternal(recoveredTransaction);
handledTransactions.add(recoveredTransaction.handle);
LOG.info("{} committed recovered transaction {}", name(), recoveredTransaction);
}
{
TXN transaction = operatorState.getPendingTransaction().handle;
checkNotNull(transaction, "Pending transaction is not expected to be null");
recoverAndAbort(transaction);
handledTransactions.add(transaction);
LOG.info(
"{} aborted recovered transaction {}",
name(),
operatorState.getPendingTransaction());
}
if (userContext.isPresent()) {
finishRecoveringContext(handledTransactions);
recoveredUserContext = true;
}
}
}
if (!recoveredUserContext) {
LOG.info("{} - no state to restore", name());
userContext = initializeUserContext();
}
this.pendingCommitTransactions.clear();
currentTransactionHolder = beginTransactionInternal();
LOG.debug("{} - started new transaction '{}'", name(), currentTransactionHolder);
}
Code review comment: I think we can skip this call as part of `toJsonNode()` and only keep it for the getter. 

Code before review:
public JsonNode toJsonNode() {
if (this.changeFeedProcessorItemAsJsonNode == null) {
this.changeFeedProcessorItemAsJsonNode = constructChangeFeedProcessorItemAsJsonNode();
}
if (this.changeFeedMetaDataInternal == null) {
this.changeFeedMetaDataInternal = Utils.getSimpleObjectMapper().convertValue(this.changeFeedMetaData, ChangeFeedMetaData.class);
}
return this.changeFeedProcessorItemAsJsonNode;
}

Line under review: if (this.changeFeedMetaDataInternal == null) {

Code after addressing the review:
public JsonNode toJsonNode() {
if (this.changeFeedProcessorItemAsJsonNode == null) {
this.changeFeedProcessorItemAsJsonNode = constructChangeFeedProcessorItemAsJsonNode();
}
return this.changeFeedProcessorItemAsJsonNode;
}
Code review comment: Will `createIfNonExistent` always have a set `Boolean` at this point? Otherwise, this will now print `null` instead of `false` when not set explicitly. Could use `getCreateIfNonExistent()` instead.

Code before review:
public String toString() {
StringBuilder string = new StringBuilder();
string.append("update of document '");
string.append(docId);
string.append("': ");
string.append("create-if-non-existent=");
string.append(createIfNonExistent);
string.append(": ");
string.append("[");
for (FieldUpdate fieldUpdate : fieldUpdates) {
string.append(fieldUpdate).append(" ");
}
string.append("]");
if (fieldPathUpdates.size() > 0) {
string.append(" [ ");
for (FieldPathUpdate up : fieldPathUpdates) {
string.append(up.toString()).append(" ");
}
string.append(" ]");
}
return string.toString();
}

Line under review: string.append(createIfNonExistent);

Code after addressing the review:
public String toString() {
StringBuilder string = new StringBuilder();
string.append("update of document '");
string.append(docId);
string.append("': ");
string.append("create-if-non-existent=");
string.append(createIfNonExistent);
string.append(": ");
string.append("[");
for (FieldUpdate fieldUpdate : fieldUpdates) {
string.append(fieldUpdate).append(" ");
}
string.append("]");
if (fieldPathUpdates.size() > 0) {
string.append(" [ ");
for (FieldPathUpdate up : fieldPathUpdates) {
string.append(up.toString()).append(" ");
}
string.append(" ]");
}
return string.toString();
}
Code review comment: ```suggestion             this.trustStorePassword = Optional.ofNullable(trustStorePassword); ```

Code before review:
public void setTrustStorePassword(String trustStorePassword) {
this.trustStorePassword = Optional.of(trustStorePassword);
}

Line under review: this.trustStorePassword = Optional.of(trustStorePassword);

Code after addressing the review:
public void setTrustStorePassword(String trustStorePassword) {
this.trustStorePassword = Optional.ofNullable(trustStorePassword);
}
Code review comment: 禁用的就不需要生成了。

Code before review:
public void toHashTree(HashTree tree, MsLoopController element, ParameterConfig config) {
final HashTree groupTree = controller(tree, element);
if (groupTree == null) {
return;
}
ConstantTimer constantTimer = getConstantTimer(element);
if (constantTimer != null) {
groupTree.add(constantTimer);
}
parseChild(groupTree, element, config);
}


Code after addressing the review:
public void toHashTree(HashTree tree, MsLoopController element, ParameterConfig config) {
if (BooleanUtils.isFalse(element.getEnable())) {
LogUtils.info("MsLoopController is disabled");
return;
}
final HashTree groupTree = controller(tree, element);
if (groupTree == null) {
return;
}
ConstantTimer constantTimer = getConstantTimer(element);
if (constantTimer != null) {
groupTree.add(constantTimer);
}
parseChild(groupTree, element, config);
}
Code review comment: Why don't we have to handle variable reference fields?

Code before review:
public void visit(BLangRecordLiteral recordLiteral) {
for (RecordLiteralNode.RecordField field : recordLiteral.fields) {
if (field.isKeyValueField()) {
BLangRecordLiteral.BLangRecordKeyValueField keyValueField =
(BLangRecordLiteral.BLangRecordKeyValueField) field;
keyValueField.key.expr = rewriteExpr(keyValueField.key.expr);
keyValueField.valueExpr = rewriteExpr(keyValueField.valueExpr);
} else if (field.getKind() != NodeKind.SIMPLE_VARIABLE_REF) {
BLangRecordLiteral.BLangRecordSpreadOperatorField spreadOpField =
(BLangRecordLiteral.BLangRecordSpreadOperatorField) field;
spreadOpField.expr = rewriteExpr(spreadOpField.expr);
}
}
result = recordLiteral;
}

Line under review: } else if (field.getKind() != NodeKind.SIMPLE_VARIABLE_REF) {

Code after addressing the review:
public void visit(BLangRecordLiteral recordLiteral) {
for (RecordLiteralNode.RecordField field : recordLiteral.fields) {
if (field.isKeyValueField()) {
BLangRecordLiteral.BLangRecordKeyValueField keyValueField =
(BLangRecordLiteral.BLangRecordKeyValueField) field;
keyValueField.key.expr = rewriteExpr(keyValueField.key.expr);
keyValueField.valueExpr = rewriteExpr(keyValueField.valueExpr);
} else if (field.getKind() != NodeKind.SIMPLE_VARIABLE_REF) {
BLangRecordLiteral.BLangRecordSpreadOperatorField spreadOpField =
(BLangRecordLiteral.BLangRecordSpreadOperatorField) field;
spreadOpField.expr = rewriteExpr(spreadOpField.expr);
}
}
result = recordLiteral;
}
Code review comment: The main reasons is the CatalogManager, FunctionManager use sessionConfiguration . If we rebuild a new Configuration, we can 't modify the values of the option for CatalogManager, FunctionManager . 

Code before review:
public void set(String key, String value) {
try {
this.sessionEnv = Environment.enrich(sessionEnv, Collections.singletonMap(key, value));
sessionConfiguration.setString(key, value);
} catch (Throwable t) {
throw new SqlExecutionException("Could not set session property.", t);
}
this.executionContext = new ExecutionContext(sessionEnv, executionContext);
}

Line under review: sessionConfiguration.setString(key, value);

Code after addressing the review:
public void set(String key, String value) {
try {
this.sessionEnv = Environment.enrich(sessionEnv, Collections.singletonMap(key, value));
sessionConfiguration.setString(key, value);
} catch (Throwable t) {
throw new SqlExecutionException("Could not set session property.", t);
}
this.executionContext = new ExecutionContext(sessionEnv, executionContext);
}
Code review comment: `this` is unnecessary which can be removed

Code before review:
public ShardingSphereSavepoint(final String name) throws SQLException {
if (name == null || name.length() == 0) {
throw new SQLException("Savepoint name can not be NULL or empty");
}
this.savepointName = name;
}

Line under review: this.savepointName = name;

Code after addressing the review:
public ShardingSphereSavepoint(final String name) throws SQLException {
if (null == name || 0 == name.length()) {
throw new SQLException("Savepoint name can not be NULL or empty");
}
savepointName = name;
}
Code review comment: assertNotNull is unnecessary assertion in this case, it is better to remove it

Code before review:
public void assertGetInstancesWithAssignedGlobalRuleBuilderClasses() {
List<GlobalRuleBuilder> configuredBuilders = new ArrayList<>(1);
FixtureGlobalRuleBuilder builder = mock(FixtureGlobalRuleBuilder.class);
configuredBuilders.add(builder);
Collection<Class<GlobalRuleBuilder>> configuredBuilderClasses = configuredBuilders.stream().map(each -> (Class<GlobalRuleBuilder>) each.getClass()).collect(Collectors.toSet());
Collection<GlobalRuleBuilder> actual = GlobalRuleBuilderFactory.getInstances(configuredBuilderClasses);
assertNotNull(actual);
assertThat(actual.size(), is(0));
}

Line under review: assertNotNull(actual);

Code after addressing the review:
public void assertGetInstancesWithAssignedGlobalRuleBuilderClasses() {
List<GlobalRuleBuilder> configuredBuilders = new ArrayList<>(1);
FixtureGlobalRuleBuilder builder = mock(FixtureGlobalRuleBuilder.class);
configuredBuilders.add(builder);
Collection<Class<GlobalRuleBuilder>> configuredBuilderClasses = configuredBuilders.stream().map(each -> (Class<GlobalRuleBuilder>) each.getClass()).collect(Collectors.toSet());
Collection<GlobalRuleBuilder> actual = GlobalRuleBuilderFactory.getInstances(configuredBuilderClasses);
assertTrue(actual.isEmpty());
}
Code review comment: Same as https://github.com/ballerina-platform/ballerina-lang/pull/35135#discussion_r819257450

Code before review:
public void visit(BLangExpressionStmt exprStmtNode, AnalyzerData data) {
SymbolEnv env = data.env;
SymbolEnv stmtEnv = new SymbolEnv(exprStmtNode, env.scope);
env.copyTo(stmtEnv);
BLangExpression expr = exprStmtNode.expr;
BType bType = typeChecker.checkExpr(expr, stmtEnv, symTable.noType, data.prevEnvs);
if (bType != symTable.nilType && bType != symTable.semanticError &&
expr.getKind() != NodeKind.FAIL &&
!types.isNeverTypeOrStructureTypeWithARequiredNeverMember(bType)) {
dlog.error(exprStmtNode.pos, DiagnosticErrorCode.ASSIGNMENT_REQUIRED, bType);
} else if (expr.getKind() == NodeKind.INVOCATION &&
types.isNeverTypeOrStructureTypeWithARequiredNeverMember(expr.getBType())) {
data.notCompletedNormally = true;
}
validateWorkerAnnAttachments(exprStmtNode.expr, data);
}

Line under review: BType bType = typeChecker.checkExpr(expr, stmtEnv, symTable.noType, data.prevEnvs);

Code after addressing the review:
public void visit(BLangExpressionStmt exprStmtNode, AnalyzerData data) {
SymbolEnv currentEnv = data.env;
SymbolEnv stmtEnv = new SymbolEnv(exprStmtNode, currentEnv.scope);
currentEnv.copyTo(stmtEnv);
BLangExpression expr = exprStmtNode.expr;
BType bType = typeChecker.checkExpr(expr, stmtEnv, data.prevEnvs);
if (bType != symTable.nilType && bType != symTable.semanticError &&
expr.getKind() != NodeKind.FAIL &&
!types.isNeverTypeOrStructureTypeWithARequiredNeverMember(bType)) {
dlog.error(exprStmtNode.pos, DiagnosticErrorCode.ASSIGNMENT_REQUIRED, bType);
} else if (expr.getKind() == NodeKind.INVOCATION &&
types.isNeverTypeOrStructureTypeWithARequiredNeverMember(expr.getBType())) {
data.notCompletedNormally = true;
}
validateWorkerAnnAttachments(exprStmtNode.expr, data);
}
Code review comment: Gotcha, thanks

Code before review:
private int computeCapacity(SectionBlock block) {
int ret = 0;
for (TemplateNode node : block.nodes) {
if (Parser.isDummyNode(node)) {
continue;
}
if (node.isText()) {
ret += node.asText().getValue().length();
} else if (node.isExpression()) {
ret += 10;
} else if (node.isSection()) {
SectionHelper helper = node.asSection().getHelper();
if (LoopSectionHelper.class.isInstance(helper)) {
ret += 10 * computeCapacity(node.asSection().blocks.get(0));
} else if (IncludeSectionHelper.class.isInstance(helper)) {
ret += 500;
} else if (UserTagSectionHelper.class.isInstance(helper)) {
ret += 200;
} else {
for (SectionBlock b : node.asSection().blocks) {
ret += computeCapacity(b);
}
}
}
}
return ret;
}

Line under review: for (TemplateNode node : block.nodes) {

Code after addressing the review:
private int computeCapacity(SectionBlock block) {
int ret = 0;
for (TemplateNode node : block.nodes) {
if (Parser.isDummyNode(node)) {
continue;
}
if (node.isText()) {
ret += node.asText().getValue().length();
} else if (node.isExpression()) {
ret += 10;
} else if (node.isSection()) {
SectionHelper helper = node.asSection().getHelper();
if (LoopSectionHelper.class.isInstance(helper)) {
ret += 10 * computeCapacity(node.asSection().blocks.get(0));
} else if (IncludeSectionHelper.class.isInstance(helper)) {
ret += 500;
} else if (UserTagSectionHelper.class.isInstance(helper)) {
ret += 200;
} else {
for (SectionBlock b : node.asSection().blocks) {
ret += computeCapacity(b);
}
}
}
}
return ret;
}
Code review comment: `LocalInputChannel` only spills when it awaits barrier. So it spills the buffer on first sight and it cannot be better on downsteam level. We could of course also move spilling lingering buffers to the upstream. It might also be an improvement for later, but it adds quite a bit of complexity as barriers also need to be propagated upstream.

Code before review:
Optional<BufferAndAvailability> getNextBuffer() throws IOException {
checkError();
ResultSubpartitionView subpartitionView = this.subpartitionView;
if (subpartitionView == null) {
if (isReleased) {
return Optional.empty();
}
subpartitionView = checkAndWaitForSubpartitionView();
}
BufferAndBacklog next = subpartitionView.getNextBuffer();
if (next == null) {
if (subpartitionView.isReleased()) {
throw new CancelTaskException("Consumed partition " + subpartitionView + " has been released.");
} else {
return Optional.empty();
}
}
Buffer buffer = next.buffer();
numBytesIn.inc(buffer.getSize());
numBuffersIn.inc();
if (buffer.isBuffer()) {
for (final long barrierId : pendingCheckpointBarriers) {
channelStateWriter.addInputData(
barrierId,
getChannelInfo(),
ChannelStateWriter.SEQUENCE_NUMBER_UNKNOWN,
CloseableIterator.ofElement(buffer.retainBuffer(), Buffer::recycleBuffer));
}
} else if (buffer.getDataType().hasPriority()) {
final AbstractEvent priorityEvent = parsePriorityEvent(buffer);
if (priorityEvent instanceof CheckpointBarrier) {
final long barrierId = ((CheckpointBarrier) priorityEvent).getId();
seenCheckpointBarriers.add(barrierId);
pendingCheckpointBarriers.remove(barrierId);
}
}
return Optional.of(new BufferAndAvailability(buffer, next.getNextDataType(), next.buffersInBacklog()));
}

Line under review: CloseableIterator.ofElement(buffer.retainBuffer(), Buffer::recycleBuffer));

Code after addressing the review:
Optional<BufferAndAvailability> getNextBuffer() throws IOException {
checkError();
ResultSubpartitionView subpartitionView = this.subpartitionView;
if (subpartitionView == null) {
if (isReleased) {
return Optional.empty();
}
subpartitionView = checkAndWaitForSubpartitionView();
}
BufferAndBacklog next = subpartitionView.getNextBuffer();
if (next == null) {
if (subpartitionView.isReleased()) {
throw new CancelTaskException("Consumed partition " + subpartitionView + " has been released.");
} else {
return Optional.empty();
}
}
Buffer buffer = next.buffer();
numBytesIn.inc(buffer.getSize());
numBuffersIn.inc();
if (buffer.getDataType().hasPriority()) {
channelStatePersister.checkForBarrier(buffer);
} else {
channelStatePersister.maybePersist(buffer);
}
return Optional.of(new BufferAndAvailability(
buffer,
next.getNextDataType(),
next.buffersInBacklog(),
next.getSequenceNumber()));
}
Code review comment: `Connection` and `Channel` are not `Autocloseable`. I'm adding a try/catch anyway.

Code before review:
public void testReadQueue() throws Exception {
final int maxNumRecords = 10;
PCollection<RabbitMqMessage> raw =
p.apply(
RabbitMqIO.read()
.withUri("amqp:
.withQueue("READ")
.withMaxNumRecords(maxNumRecords));
PCollection<byte[]> output = raw.apply(ParDo.of(new ConverterFn()));
List<byte[]> records = generateRecords(maxNumRecords);
PAssert.that(output).containsInAnyOrder(records);
ConnectionFactory connectionFactory = new ConnectionFactory();
connectionFactory.setUri("amqp:
Connection connection = connectionFactory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare("READ", false, false, false, null);
for (byte[] record : records) {
channel.basicPublish("", "READ", null, record);
}
p.run();
channel.close();
connection.close();
}

Line under review: channel.close();

Code after addressing the review:
public void testReadQueue() throws Exception {
final int maxNumRecords = 10;
PCollection<RabbitMqMessage> raw =
p.apply(
RabbitMqIO.read()
.withUri("amqp:
.withQueue("READ")
.withMaxNumRecords(maxNumRecords));
PCollection<String> output =
raw.apply(
MapElements.into(TypeDescriptors.strings())
.via(
(RabbitMqMessage message) ->
new String(message.getBody(), StandardCharsets.UTF_8)));
List<String> records =
generateRecords(maxNumRecords)
.stream()
.map(record -> new String(record, StandardCharsets.UTF_8))
.collect(Collectors.toList());
PAssert.that(output).containsInAnyOrder(records);
ConnectionFactory connectionFactory = new ConnectionFactory();
connectionFactory.setUri("amqp:
Connection connection = null;
Channel channel = null;
try {
connection = connectionFactory.newConnection();
channel = connection.createChannel();
channel.queueDeclare("READ", false, false, false, null);
for (String record : records) {
channel.basicPublish("", "READ", null, record.getBytes(StandardCharsets.UTF_8));
}
p.run();
} finally {
if (channel != null) {
channel.close();
}
if (connection != null) {
connection.close();
}
}
}
Code review comment: In async samples, we don't generally use `block()`.

Code before review:
public static void main(String[] args) throws InterruptedException {
String azureOpenaiKey = "{azure-open-ai-key}";
String endpoint = "{azure-open-ai-endpoint}";
String deploymentOrModelId = "{azure-open-ai-deployment-model-id}";
OpenAIAsyncClient client = new OpenAIClientBuilder()
.endpoint(endpoint)
.credential(new AzureKeyCredential(azureOpenaiKey))
.buildAsyncClient();
String prompt = "Tell me 3 facts about pineapples";
Sinks.Empty<Void> completionSink = Sinks.empty();
client.getCompletions(deploymentOrModelId, prompt)
.timeout(Duration.ofSeconds(10))
.subscribe(
completions -> {
for (Choice choice : completions.getChoices()) {
System.out.printf("%s.%n", choice.getText());
}
},
error -> System.err.println("There was an error getting completions." + error),
() -> completionSink.emitEmpty(Sinks.EmitFailureHandler.FAIL_FAST)
);
completionSink.asMono().block();
}

Line under review: completionSink.asMono().block();

Code after addressing the review:
public static void main(String[] args) throws InterruptedException {
String azureOpenAIKey = "{azure-open-ai-key}";
String endpoint = "{azure-open-ai-endpoint}";
String deploymentOrModelId = "{azure-open-ai-deployment-model-id}";
OpenAIAsyncClient client = new OpenAIClientBuilder()
.endpoint(endpoint)
.credential(new AzureKeyCredential(azureOpenAIKey))
.buildAsyncClient();
String prompt = "Tell me 3 facts about pineapples";
client.getCompletions(deploymentOrModelId, prompt)
.subscribe(
completions -> {
for (Choice choice : completions.getChoices()) {
System.out.printf("%s.%n", choice.getText());
}
},
error -> System.err.println("There was an error getting completions." + error),
() -> System.out.println("Completed called getCompletions.")
);
TimeUnit.SECONDS.sleep(10);
}
Code review comment: It is inconsistent to use `absoluteTimeMillis()` here and `relativeTimeMillis()` within `rescheduleTrigger()`.

Code before review:
public void setIsProcessingBacklog(OperatorID operatorID, boolean isProcessingBacklog) {
if (isProcessingBacklog) {
backlogOperators.add(operatorID);
} else {
backlogOperators.remove(operatorID);
}
if (getCurrentCheckpointInterval() != Long.MAX_VALUE) {
long newNextCheckpointTriggeringTime =
clock.absoluteTimeMillis() + getCurrentCheckpointInterval();
if (newNextCheckpointTriggeringTime < nextCheckpointTriggeringRelativeTime) {
rescheduleTrigger(getCurrentCheckpointInterval());
}
}
}

Line under review: clock.absoluteTimeMillis() + getCurrentCheckpointInterval();

Code after addressing the review:
public void setIsProcessingBacklog(OperatorID operatorID, boolean isProcessingBacklog) {
synchronized (lock) {
if (isProcessingBacklog) {
backlogOperators.add(operatorID);
} else {
backlogOperators.remove(operatorID);
}
long currentCheckpointInterval = getCurrentCheckpointInterval();
if (currentCheckpointInterval
!= CheckpointCoordinatorConfiguration.DISABLED_CHECKPOINT_INTERVAL) {
long currentRelativeTime = clock.relativeTimeMillis();
if (currentRelativeTime + currentCheckpointInterval
< nextCheckpointTriggeringRelativeTime) {
rescheduleTrigger(currentRelativeTime, currentCheckpointInterval);
}
}
}
}
Code review comment: The `CompletionStage` will be computed eagerly when the method is invoked while `Uni` is supposed to be lazy.   This can be fixed using a `Supplier`:  (:warning: untested suggestion :warning:) ```suggestion         return Uni.createFrom().completionStage(new Supplier<>() {                 @Override                 public CompletionStage<?> get() {                     return cache.clearAsync();                 }             }); ```

Code before review:
private Uni<Void> invalidateAll(CacheInvalidateAll binding) {
RemoteCache cache = cacheManager.getCache(binding.cacheName());
LOGGER.debugf("Invalidating all entries from cache [%s]", binding.cacheName());
return Uni.createFrom().completionStage(cache.clearAsync());
}

Line under review: return Uni.createFrom().completionStage(cache.clearAsync());

Code after addressing the review:
private Uni<Void> invalidateAll(CacheInvalidateAll binding) {
RemoteCache cache = cacheManager.getCache(binding.cacheName());
LOGGER.debugf("Invalidating all entries from cache [%s]", binding.cacheName());
return Uni.createFrom().completionStage(new Supplier<>() {
@Override
public CompletionStage<Void> get() {
return cache.clearAsync();
}
});
}
Code review comment: line 637, 638 LOG.debug can merged.

Code before review:
public TLoadTxnBeginResult loadTxnBegin(TLoadTxnBeginRequest request) throws TException {
String clientAddr = getClientAddrAsString();
LOG.debug("receive txn begin request, db: {}, tbl: {}, label: {}, backend: {}",
request.getDb(), request.getTbl(), request.getLabel(), clientAddr);
LOG.debug("txn begin request: {}", request);
TLoadTxnBeginResult result = new TLoadTxnBeginResult();
TStatus status = new TStatus(TStatusCode.OK);
result.setStatus(status);
try {
result.setTxnId(loadTxnBeginImpl(request, clientAddr));
} catch (DuplicatedRequestException e) {
LOG.warn("duplicate request for stream load. request id: {}, txn: {}", e.getDuplicatedRequestId(), e.getTxnId());
result.setTxnId(e.getTxnId());
} catch (LabelAlreadyUsedException e) {
status.setStatusCode(TStatusCode.LABEL_ALREADY_EXISTS);
status.addToErrorMsgs(e.getMessage());
result.setJobStatus(e.getJobStatus());
} catch (UserException e) {
LOG.warn("failed to begin: {}", e.getMessage());
status.setStatusCode(TStatusCode.ANALYSIS_ERROR);
status.addToErrorMsgs(e.getMessage());
} catch (Throwable e) {
LOG.warn("catch unknown result.", e);
status.setStatusCode(TStatusCode.INTERNAL_ERROR);
status.addToErrorMsgs(Strings.nullToEmpty(e.getMessage()));
return result;
}
return result;
}

Line under review: LOG.debug("receive txn begin request, db: {}, tbl: {}, label: {}, backend: {}",

Code after addressing the review:
public TLoadTxnBeginResult loadTxnBegin(TLoadTxnBeginRequest request) throws TException {
String clientAddr = getClientAddrAsString();
LOG.debug("receive txn begin request: {}, backend: {}", request, clientAddr);
TLoadTxnBeginResult result = new TLoadTxnBeginResult();
TStatus status = new TStatus(TStatusCode.OK);
result.setStatus(status);
try {
result.setTxnId(loadTxnBeginImpl(request, clientAddr));
} catch (DuplicatedRequestException e) {
LOG.warn("duplicate request for stream load. request id: {}, txn: {}", e.getDuplicatedRequestId(), e.getTxnId());
result.setTxnId(e.getTxnId());
} catch (LabelAlreadyUsedException e) {
status.setStatusCode(TStatusCode.LABEL_ALREADY_EXISTS);
status.addToErrorMsgs(e.getMessage());
result.setJobStatus(e.getJobStatus());
} catch (UserException e) {
LOG.warn("failed to begin: {}", e.getMessage());
status.setStatusCode(TStatusCode.ANALYSIS_ERROR);
status.addToErrorMsgs(e.getMessage());
} catch (Throwable e) {
LOG.warn("catch unknown result.", e);
status.setStatusCode(TStatusCode.INTERNAL_ERROR);
status.addToErrorMsgs(Strings.nullToEmpty(e.getMessage()));
return result;
}
return result;
}
Code review comment: The parameter is the estimated initial capacity.  The implementation will automatically adjust the size of the table to be a mathematical product of the initial capacity and the load factor.  IOW if you expect to store 100 elements, pass in 100 as the initial capacity.

Code before review:
public HashSet<T> apply(final int value) {
return new HashSet<>(value);
}

Line under review: return new HashSet<>(value);

Code after addressing the review:
public HashSet<T> apply(final int value) {
return new HashSet<>(getInitialCapacityFromExpectedSize(value));
}
Code review comment: `unusedAlgorithmsCollection` name could be `actual`

Code before review:
void assertFind() {
ShardingRuleConfiguration ruleConfig = new ShardingRuleConfiguration();
ShardingTableRuleConfiguration shardingTableRuleConfiguration = getShardingTableRuleConfiguration();
Map<String, AlgorithmConfiguration> allAlgorithms = getAlgorithms();
ruleConfig.getTables().add(shardingTableRuleConfiguration);
ruleConfig.getShardingAlgorithms().putAll(allAlgorithms);
ruleConfig.setDefaultDatabaseShardingStrategy(new StandardShardingStrategyConfiguration("order_id", USED_DATABASE_SHARDING_DEFAULT_ALGORITHM));
ruleConfig.setDefaultTableShardingStrategy(new StandardShardingStrategyConfiguration("order_id", USED_TABLE_SHARDING_DEFAULT_ALGORITHM));
Collection<String> unusedAlgorithmsCollection = UnusedAlgorithmFinder.find(ruleConfig);
assertNotNull(unusedAlgorithmsCollection);
assertThat(unusedAlgorithmsCollection.size(), is(1));
assertTrue(unusedAlgorithmsCollection.contains(UNUSED_ALGORITHM));
}

Line under review: Collection<String> unusedAlgorithmsCollection = UnusedAlgorithmFinder.find(ruleConfig);

Code after addressing the review:
void assertFind() {
ShardingRuleConfiguration ruleConfig = new ShardingRuleConfiguration();
ShardingTableRuleConfiguration shardingTableRuleConfig = getShardingTableRuleConfiguration();
ruleConfig.getTables().add(shardingTableRuleConfig);
ruleConfig.getShardingAlgorithms().putAll(getAlgorithms());
ruleConfig.setDefaultDatabaseShardingStrategy(new StandardShardingStrategyConfiguration("order_id", USED_DATABASE_SHARDING_DEFAULT_ALGORITHM));
ruleConfig.setDefaultTableShardingStrategy(new StandardShardingStrategyConfiguration("order_id", USED_TABLE_SHARDING_DEFAULT_ALGORITHM));
Collection<String> actual = UnusedAlgorithmFinder.find(ruleConfig);
assertNotNull(actual);
assertThat(actual.size(), is(1));
assertTrue(actual.contains(UNUSED_ALGORITHM));
}
Code review comment: I think I fixed it in b83b280ce2fb493eb647ffa589613c0b0362f39a which is part of #5774 

Code before review:
private ExpectedJobIdJobManagerRunnerFactory(JobID expectedJobId) {
this.expectedJobId = expectedJobId;
}

Line under review: this.expectedJobId = expectedJobId;

Code after addressing the review:
private ExpectedJobIdJobManagerRunnerFactory(JobID expectedJobId) {
this.expectedJobId = expectedJobId;
}
Code review comment: Could we add requestId generator? There're much hard-coded code for now

Code before review:
public void userEventTriggered(final ChannelHandlerContext ctx, final Object evt) {
if (evt instanceof CreateSubscriptionEvent) {
Builder builder = CDCRequest.newBuilder();
builder.setCreateSubscription(buildCreateSubscriptionRequest());
builder.setRequestId(UUID.randomUUID().toString());
ctx.writeAndFlush(builder.build());
}
}

Line under review: builder.setRequestId(UUID.randomUUID().toString());

Code after addressing the review:
public void userEventTriggered(final ChannelHandlerContext ctx, final Object evt) {
if (evt instanceof CreateSubscriptionEvent) {
CDCRequest request = CDCRequest.newBuilder().setCreateSubscription(buildCreateSubscriptionRequest()).setRequestId(RequestIdUtil.generateRequestId()).build();
ctx.writeAndFlush(request);
}
}
Code review comment: Two catch branches are identical. So we don't need explicitly catch UnsupportedEncodingException here 

Code before review:
private String getReturnValue(HTTPCarbonMessage response) {
Reader reader;
final int bufferSize = 1024;
final char[] buffer = new char[bufferSize];
final StringBuilder out = new StringBuilder();
try {
reader = new InputStreamReader(new HttpMessageDataStreamer(response).getInputStream(), UTF_8);
while (true) {
int size = reader.read(buffer, 0, buffer.length);
if (size < 0) {
break;
}
out.append(buffer, 0, size);
}
} catch (UnsupportedEncodingException e) {
LOG.error("Error occured while reading the response value in getReturnValue", e.getMessage());
} catch (IOException e) {
LOG.error("Error occured while reading the response value in getReturnValue", e.getMessage());
}
return out.toString();
}

Line under review: } catch (IOException e) {

Code after addressing the review:
private String getReturnValue(HTTPCarbonMessage response) {
Reader reader;
final int bufferSize = 1024;
final char[] buffer = new char[bufferSize];
final StringBuilder out = new StringBuilder();
try {
reader = new InputStreamReader(new HttpMessageDataStreamer(response).getInputStream(), UTF_8);
while (true) {
int size = reader.read(buffer, 0, buffer.length);
if (size < 0) {
break;
}
out.append(buffer, 0, size);
}
} catch (IOException e) {
LOG.error("Error occured while reading the response value in getReturnValue", e.getMessage());
}
return out.toString();
}
Code review comment: Shall we have some tests for both values with same type, in order to cover these lines?

Code before review:
public static boolean isReferenceEqual(Object lhsValue, Object rhsValue) {
if (lhsValue == rhsValue) {
return true;
}
if (lhsValue == null || rhsValue == null) {
return false;
}
Type lhsType = getType(lhsValue);
Type rhsType = getType(rhsValue);
switch(lhsType.getTag()) {
case TypeTags.INT_TAG:
if (rhsType.getTag() != TypeTags.BYTE_TAG || rhsType.getTag() != TypeTags.INT_TAG) {
return false;
}
return lhsValue.equals(((Number) rhsValue).longValue());
case TypeTags.BYTE_TAG:
if (rhsType.getTag() != TypeTags.BYTE_TAG || rhsType.getTag() != TypeTags.INT_TAG) {
return false;
}
return lhsValue.equals(((Number) rhsValue).byteValue());
case TypeTags.FLOAT_TAG:
if (rhsType.getTag() != TypeTags.FLOAT_TAG) {
return false;
}
return lhsValue.equals(((Number) rhsValue).doubleValue());
case TypeTags.DECIMAL_TAG:
if (rhsType.getTag() != TypeTags.DECIMAL_TAG) {
return false;
}
return checkDecimalExactEqual((DecimalValue) lhsValue, (DecimalValue) rhsValue);
case TypeTags.BOOLEAN_TAG:
case TypeTags.STRING_TAG:
return lhsValue.equals(rhsValue);
}
if (TypeTags.isXMLTypeTag(lhsType.getTag()) && TypeTags.isXMLTypeTag(rhsType.getTag())) {
return isXMLValueRefEqual((XmlValue) lhsValue, (XmlValue) rhsValue);
}
if (isHandleType(lhsType) && isHandleType(rhsType)) {
return isHandleValueRefEqual(lhsValue, rhsValue);
}
return false;
}

Line under review: return lhsValue.equals(((Number) rhsValue).longValue());

Code after addressing the review:
public static boolean isReferenceEqual(Object lhsValue, Object rhsValue) {
if (lhsValue == rhsValue) {
return true;
}
if (lhsValue == null || rhsValue == null) {
return false;
}
Type lhsType = getType(lhsValue);
Type rhsType = getType(rhsValue);
switch (lhsType.getTag()) {
case TypeTags.FLOAT_TAG:
if (rhsType.getTag() != TypeTags.FLOAT_TAG) {
return false;
}
return lhsValue.equals(((Number) rhsValue).doubleValue());
case TypeTags.DECIMAL_TAG:
if (rhsType.getTag() != TypeTags.DECIMAL_TAG) {
return false;
}
return checkDecimalExactEqual((DecimalValue) lhsValue, (DecimalValue) rhsValue);
case TypeTags.INT_TAG:
case TypeTags.BYTE_TAG:
case TypeTags.BOOLEAN_TAG:
case TypeTags.STRING_TAG:
return isEqual(lhsValue, rhsValue);
case TypeTags.XML_TAG:
case TypeTags.XML_COMMENT_TAG:
case TypeTags.XML_ELEMENT_TAG:
case TypeTags.XML_PI_TAG:
case TypeTags.XML_TEXT_TAG:
if (!TypeTags.isXMLTypeTag(rhsType.getTag())) {
return false;
}
return isXMLValueRefEqual((XmlValue) lhsValue, (XmlValue) rhsValue);
case TypeTags.HANDLE_TAG:
if (rhsType.getTag() != TypeTags.HANDLE_TAG) {
return false;
}
return isHandleValueRefEqual(lhsValue, rhsValue);
}
return false;
}
Code review comment: You mean that we should enforce it when it's 307?

Code before review:
void shouldNotRedirectOnPostMethodsByDefault() {
RedirectingResourceClient302 client302 = RestClientBuilder.newBuilder()
.baseUri(uri)
.followRedirects(true)
.build(RedirectingResourceClient302.class);
assertThat(client302.post().getStatus()).isEqualTo(302);
RedirectingResourceClient307 client307 = RestClientBuilder.newBuilder()
.baseUri(uri)
.followRedirects(true)
.build(RedirectingResourceClient307.class);
assertThat(client307.post(1).getStatus()).isEqualTo(307);
}

Line under review: .followRedirects(true)

Code after addressing the review:
void shouldNotRedirectOnPostMethodsByDefault() {
RedirectingResourceClient302 client302 = RestClientBuilder.newBuilder()
.baseUri(uri)
.followRedirects(true)
.build(RedirectingResourceClient302.class);
assertThat(client302.post().getStatus()).isEqualTo(302);
RedirectingResourceClient307 client307 = RestClientBuilder.newBuilder()
.baseUri(uri)
.followRedirects(true)
.build(RedirectingResourceClient307.class);
assertThat(client307.post(1).getStatus()).isEqualTo(307);
}
Code review comment: I now see how I wrote this very inefficiently, these fields could easily have been `AtomicBoolean`s or even plain `boolean`s :-) But that's just an observation, the test works just fine.

Code before review:
public void test() {
assertEquals(0, MyDependentBean.createdCounter.get());
assertEquals(0, MyDependentBean.destroyedCounter.get());
assertEquals(0, MySingletonBean.createdCounter.get());
assertEquals(0, MySingletonBean.destroyedCounter.get());
InstanceHandle<MyDependentBean> dependentBean = Arc.container().select(MyDependentBean.class).getHandle();
InstanceHandle<MySingletonBean> singletonBean = Arc.container().select(MySingletonBean.class).getHandle();
dependentBean.get();
singletonBean.get();
assertEquals(1, MyDependentBean.createdCounter.get());
assertEquals(0, MyDependentBean.destroyedCounter.get());
assertEquals(1, MySingletonBean.createdCounter.get());
assertEquals(0, MySingletonBean.destroyedCounter.get());
dependentBean.destroy();
singletonBean.destroy();
assertEquals(1, MyDependentBean.createdCounter.get());
assertEquals(1, MyDependentBean.destroyedCounter.get());
assertEquals(1, MySingletonBean.createdCounter.get());
assertEquals(1, MySingletonBean.destroyedCounter.get());
}

Line under review: assertEquals(1, MySingletonBean.destroyedCounter.get());

Code after addressing the review:
public void test() {
assertEquals(0, MyDependentBean.createdCounter.get());
assertEquals(0, MyDependentBean.destroyedCounter.get());
assertEquals(0, MySingletonBean.createdCounter.get());
assertEquals(0, MySingletonBean.destroyedCounter.get());
InstanceHandle<MyDependentBean> dependentBean = Arc.container().select(MyDependentBean.class).getHandle();
InstanceHandle<MySingletonBean> singletonBean = Arc.container().select(MySingletonBean.class).getHandle();
dependentBean.get();
singletonBean.get();
assertEquals(1, MyDependentBean.createdCounter.get());
assertEquals(0, MyDependentBean.destroyedCounter.get());
assertEquals(1, MySingletonBean.createdCounter.get());
assertEquals(0, MySingletonBean.destroyedCounter.get());
dependentBean.destroy();
singletonBean.destroy();
assertEquals(1, MyDependentBean.createdCounter.get());
assertEquals(1, MyDependentBean.destroyedCounter.get());
assertEquals(1, MySingletonBean.createdCounter.get());
assertEquals(1, MySingletonBean.destroyedCounter.get());
}
Code review comment: `FileMergingManager` is created for each TM, so `initFileSystem()` is only called once right?  So,  1. in what case initFileSystem will be called several times? 2. what if a TM contains different jobs (Base CP directory maybe different)

Code before review:
public void registerSubtaskForSharedStates(SubtaskKey subtaskKey) {
String managedDirName = subtaskKey.getManagedDirName();
Path managedPath = new Path(sharedStateDir, managedDirName);
if (!managedSharedStateDir.containsKey(subtaskKey)) {
createManagedDirectory(managedPath);
managedSharedStateDir.put(subtaskKey, managedPath);
}
}

Line under review: }

Code after addressing the review:
public void registerSubtaskForSharedStates(SubtaskKey subtaskKey) {
String managedDirName = subtaskKey.getManagedDirName();
Path managedPath = new Path(sharedStateDir, managedDirName);
if (!managedSharedStateDir.containsKey(subtaskKey)) {
createManagedDirectory(managedPath);
managedSharedStateDir.put(subtaskKey, managedPath);
}
}
Code review comment: is this conventional to use `Context.NONE` as a value even though it's a different type from what `SPAN_CONTEXT_KEY` normally holds?

Code before review:
private EventData traceMessageSpan(EventData eventData) {
Optional<Object> eventContextData = eventData.getContext().getData(SPAN_CONTEXT_KEY);
if (eventContextData.isPresent()) {
return eventData;
} else {
Context eventContext = eventData.getContext()
.addData(AZ_TRACING_NAMESPACE_KEY, AZ_NAMESPACE_VALUE)
.addData(ENTITY_PATH_KEY, this.entityPath)
.addData(HOST_NAME_KEY, this.hostname);
eventContext = tracerProvider.startSpan(AZ_TRACING_SERVICE_NAME, eventContext,
ProcessKind.MESSAGE);
Optional<Object> eventDiagnosticIdOptional = eventContext.getData(DIAGNOSTIC_ID_KEY);
if (eventDiagnosticIdOptional.isPresent()) {
eventData.getProperties().put(DIAGNOSTIC_ID_KEY, eventDiagnosticIdOptional.get().toString());
tracerProvider.endSpan(eventContext, Signal.complete());
eventData.addContext(SPAN_CONTEXT_KEY, eventContext.getData(SPAN_CONTEXT_KEY).orElse(Context.NONE));
}
}
return eventData;
}

Line under review: eventData.addContext(SPAN_CONTEXT_KEY, eventContext.getData(SPAN_CONTEXT_KEY).orElse(Context.NONE));

Code after addressing the review:
private EventData traceMessageSpan(EventData eventData) {
Optional<Object> eventContextData = eventData.getContext().getData(SPAN_CONTEXT_KEY);
if (eventContextData.isPresent()) {
return eventData;
} else {
Context eventContext = eventData.getContext()
.addData(AZ_TRACING_NAMESPACE_KEY, AZ_NAMESPACE_VALUE)
.addData(ENTITY_PATH_KEY, this.entityPath)
.addData(HOST_NAME_KEY, this.hostname);
eventContext = tracerProvider.startSpan(AZ_TRACING_SERVICE_NAME, eventContext,
ProcessKind.MESSAGE);
Optional<Object> eventDiagnosticIdOptional = eventContext.getData(DIAGNOSTIC_ID_KEY);
if (eventDiagnosticIdOptional.isPresent()) {
eventData.getProperties().put(DIAGNOSTIC_ID_KEY, eventDiagnosticIdOptional.get().toString());
tracerProvider.endSpan(eventContext, Signal.complete());
Object spanContext = eventContext.getData(SPAN_CONTEXT_KEY).orElse(null);
if (spanContext != null) {
eventData.addContext(SPAN_CONTEXT_KEY, spanContext);
}
}
}
return eventData;
}
Code review comment: Better to delete code directly.

Code before review:
public void createTable(CreateTableStmt stmt) throws DdlException {
String engineName = stmt.getEngineName();
String dbName = stmt.getDbName();
String tableName = stmt.getTableName();
Database db = getDb(stmt.getDbName());
if (db == null) {
ErrorReport.reportDdlException(ErrorCode.ERR_BAD_DB_ERROR, dbName);
}
if (!stmt.isExternal()) {
Catalog.getCurrentSystemInfo().checkClusterCapacity(stmt.getClusterName());
db.checkQuota();
}
db.readLock();
try {
if (db.getTable(tableName) != null) {
if (stmt.isSetIfNotExists()) {
LOG.info("create table[{}] which already exists", tableName);
return;
} else {
ErrorReport.reportDdlException(ErrorCode.ERR_TABLE_EXISTS_ERROR, tableName);
}
}
} finally {
db.readUnlock();
}
if (engineName.equals("olap")) {
createOlapTable(db, stmt);
return;
} else if (engineName.equals("mysql")) {
createMysqlTable(db, stmt);
return;
} else if (engineName.equals("broker")) {
throw new DdlException("Broker table is deprecated.");
} else if (engineName.equalsIgnoreCase("elasticsearch") || engineName.equalsIgnoreCase("es")) {
createEsTable(db, stmt);
return;
} else if (engineName.equalsIgnoreCase("hive")) {
createHiveTable(db, stmt);
return;
} else {
ErrorReport.reportDdlException(ErrorCode.ERR_UNKNOWN_STORAGE_ENGINE, engineName);
}
Preconditions.checkState(false);
}

Line under review: throw new DdlException("Broker table is deprecated.");

Code after addressing the review:
public void createTable(CreateTableStmt stmt) throws DdlException {
String engineName = stmt.getEngineName();
String dbName = stmt.getDbName();
String tableName = stmt.getTableName();
Database db = getDb(stmt.getDbName());
if (db == null) {
ErrorReport.reportDdlException(ErrorCode.ERR_BAD_DB_ERROR, dbName);
}
if (!stmt.isExternal()) {
Catalog.getCurrentSystemInfo().checkClusterCapacity(stmt.getClusterName());
db.checkQuota();
}
db.readLock();
try {
if (db.getTable(tableName) != null) {
if (stmt.isSetIfNotExists()) {
LOG.info("create table[{}] which already exists", tableName);
return;
} else {
ErrorReport.reportDdlException(ErrorCode.ERR_TABLE_EXISTS_ERROR, tableName);
}
}
} finally {
db.readUnlock();
}
if (engineName.equals("olap")) {
createOlapTable(db, stmt);
return;
} else if (engineName.equals("mysql")) {
createMysqlTable(db, stmt);
return;
} else if (engineName.equalsIgnoreCase("elasticsearch") || engineName.equalsIgnoreCase("es")) {
createEsTable(db, stmt);
return;
} else if (engineName.equalsIgnoreCase("hive")) {
createHiveTable(db, stmt);
return;
} else {
ErrorReport.reportDdlException(ErrorCode.ERR_UNKNOWN_STORAGE_ENGINE, engineName);
}
Preconditions.checkState(false);
}
Code review comment: This probably belongs to `CalciteUtils`, we have similar casting logic there

Code before review:
public void processElement(ProcessContext c) {
assert se != null;
try {
se.evaluate(new Object[] {outputSchema, c, CONTEXT_INSTANCE});
} catch (InvocationTargetException e) {
throw new RuntimeException(
"CalcFn failed to evaluate: " + processElementBlock, e.getCause());
}
}

Line under review: throw new RuntimeException(

Code after addressing the review:
public void processElement(ProcessContext c) {
assert se != null;
try {
se.evaluate(new Object[] {outputSchema, c, CONTEXT_INSTANCE});
} catch (InvocationTargetException e) {
throw new RuntimeException(
"CalcFn failed to evaluate: " + processElementBlock, e.getCause());
}
}
Code review comment: Done

Code before review:
public boolean onEmitFailure(SignalType signalType, Sinks.EmitResult emitResult) {
logger.debug("SerializedEmitFailureHandler.onEmitFailure - Signal:{}, Result: {}", signalType, emitResult);
if (emitResult.equals(Sinks.EmitResult.FAIL_NON_SERIALIZED)) {
return true;
}
return false;
}

Line under review: return false;

Code after addressing the review:
public boolean onEmitFailure(SignalType signalType, Sinks.EmitResult emitResult) {
if (emitResult.equals(Sinks.EmitResult.FAIL_NON_SERIALIZED)) {
logger.debug("SerializedEmitFailureHandler.onEmitFailure - Signal:{}, Result: {}", signalType, emitResult);
return true;
}
logger.error("SerializedEmitFailureHandler.onEmitFailure - Signal:{}, Result: {}", signalType, emitResult);
return false;
}
Code review comment: Great, I didn't notice this.

Code before review:
Set<HostSpec> getHostSpecs() {
return getHosts().stream()
.map(host -> new HostSpec(host.getHostName(), Collections.emptyList(),
host.getFlavor(), host.primaryClusterMembership()))
.collect(Collectors.toCollection(LinkedHashSet::new));
}

Line under review: return getHosts().stream()

Code after addressing the review:
Set<HostSpec> getHostSpecs() {
return getHosts().stream()
.map(host -> new HostSpec(host.getHostName(), Collections.emptyList(),
host.getFlavor(), host.primaryClusterMembership()))
.collect(Collectors.toCollection(LinkedHashSet::new));
}