clolov commented on code in PR #18371:
URL: https://github.com/apache/kafka/pull/18371#discussion_r1904100155
##########
connect/api/src/main/java/org/apache/kafka/connect/data/SchemaProjector.java:
##########
@@ -78,25 +79,13 @@ public static Object project(Schema source, Object record,
Schema target) throws
}
private static Object projectRequiredSchema(Schema source, Object record,
Schema target) throws SchemaProjectorException {
- switch (target.type()) {
- case INT8:
- case INT16:
- case INT32:
- case INT64:
- case FLOAT32:
- case FLOAT64:
- case BOOLEAN:
- case BYTES:
- case STRING:
- return projectPrimitive(source, record, target);
- case STRUCT:
- return projectStruct(source, (Struct) record, target);
- case ARRAY:
- return projectArray(source, record, target);
- case MAP:
- return projectMap(source, record, target);
- }
- return null;
Review Comment:
In other places you have translated this to `default -> null` in the new
syntax. Shouldn't this be the same or am I missing something obvious?
##########
connect/api/src/main/java/org/apache/kafka/connect/data/Values.java:
##########
@@ -431,33 +431,20 @@ protected static Object convertTo(Schema toSchema, Schema
fromSchema, Object val
}
throw new DataException("Unable to convert a null value to a
schema that requires a value");
}
- switch (toSchema.type()) {
- case BYTES:
- return convertMaybeLogicalBytes(toSchema, value);
- case STRING:
- return convertToString(fromSchema, value);
- case BOOLEAN:
- return convertToBoolean(fromSchema, value);
- case INT8:
- return convertToByte(fromSchema, value);
- case INT16:
- return convertToShort(fromSchema, value);
- case INT32:
- return convertMaybeLogicalInteger(toSchema, fromSchema, value);
- case INT64:
- return convertMaybeLogicalLong(toSchema, fromSchema, value);
- case FLOAT32:
- return convertToFloat(fromSchema, value);
- case FLOAT64:
- return convertToDouble(fromSchema, value);
- case ARRAY:
- return convertToArray(toSchema, value);
- case MAP:
- return convertToMapInternal(toSchema, value);
- case STRUCT:
- return convertToStructInternal(toSchema, value);
- }
- throw new DataException("Unable to convert " + value + " (" +
value.getClass() + ") to " + toSchema);
Review Comment:
For my curiosity, will the exception here not change with the new syntax? If
it changes, do upper layers handle it correctly?
##########
storage/src/test/java/org/apache/kafka/server/log/remote/storage/LocalTieredStorage.java:
##########
@@ -539,35 +539,23 @@ private static void checkArgument(final boolean valid,
final String message, fin
}
private EventType getEventTypeForFetch(IndexType indexType) {
- switch (indexType) {
- case OFFSET:
- return FETCH_OFFSET_INDEX;
- case TIMESTAMP:
- return FETCH_TIME_INDEX;
- case PRODUCER_SNAPSHOT:
- return FETCH_PRODUCER_SNAPSHOT;
- case TRANSACTION:
- return FETCH_TRANSACTION_INDEX;
- case LEADER_EPOCH:
- return FETCH_LEADER_EPOCH_CHECKPOINT;
- }
- return FETCH_SEGMENT;
Review Comment:
Is this unreachable?
##########
server-common/src/main/java/org/apache/kafka/server/common/KRaftVersion.java:
##########
@@ -82,28 +79,23 @@ public Map<String, Short> dependencies() {
}
public short quorumStateVersion() {
- switch (this) {
- case KRAFT_VERSION_0:
- return (short) 0;
- case KRAFT_VERSION_1:
- return (short) 1;
- }
- throw new IllegalStateException("Unsupported KRaft feature level: " +
this);
Review Comment:
Is this unreachable?
##########
metadata/src/main/java/org/apache/kafka/metadata/storage/Formatter.java:
##########
@@ -459,17 +459,12 @@ enum DirectoryType {
DYNAMIC_METADATA_VOTER_DIRECTORY;
String description() {
- switch (this) {
- case LOG_DIRECTORY:
- return "data directory";
- case STATIC_METADATA_DIRECTORY:
- return "metadata directory";
- case DYNAMIC_METADATA_NON_VOTER_DIRECTORY:
- return "dynamic metadata directory";
- case DYNAMIC_METADATA_VOTER_DIRECTORY:
- return "dynamic metadata voter directory";
- }
- throw new RuntimeException("invalid enum type " + this);
Review Comment:
Is this unreachable?
##########
storage/src/test/java/org/apache/kafka/server/log/remote/storage/LocalTieredStorage.java:
##########
@@ -539,35 +539,23 @@ private static void checkArgument(final boolean valid,
final String message, fin
}
private EventType getEventTypeForFetch(IndexType indexType) {
- switch (indexType) {
- case OFFSET:
- return FETCH_OFFSET_INDEX;
- case TIMESTAMP:
- return FETCH_TIME_INDEX;
- case PRODUCER_SNAPSHOT:
- return FETCH_PRODUCER_SNAPSHOT;
- case TRANSACTION:
- return FETCH_TRANSACTION_INDEX;
- case LEADER_EPOCH:
- return FETCH_LEADER_EPOCH_CHECKPOINT;
- }
- return FETCH_SEGMENT;
+ return switch (indexType) {
+ case OFFSET -> FETCH_OFFSET_INDEX;
+ case TIMESTAMP -> FETCH_TIME_INDEX;
+ case PRODUCER_SNAPSHOT -> FETCH_PRODUCER_SNAPSHOT;
+ case TRANSACTION -> FETCH_TRANSACTION_INDEX;
+ case LEADER_EPOCH -> FETCH_LEADER_EPOCH_CHECKPOINT;
+ };
}
private RemoteLogSegmentFileset.RemoteLogSegmentFileType
getLogSegmentFileType(IndexType indexType) {
- switch (indexType) {
- case OFFSET:
- return OFFSET_INDEX;
- case TIMESTAMP:
- return TIME_INDEX;
- case PRODUCER_SNAPSHOT:
- return PRODUCER_SNAPSHOT;
- case TRANSACTION:
- return TRANSACTION_INDEX;
- case LEADER_EPOCH:
- return LEADER_EPOCH_CHECKPOINT;
- }
- return SEGMENT;
Review Comment:
Is this unreachable?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]