Code review comment: `getInt64` returns a `Long`, so I believe that will allow you to remove the `castIfNecessary`?

Code before review:
private static Expression value(Expression value, Schema.FieldType type) {
if (type.getTypeName().isLogicalType()) {
String logicalId = type.getLogicalType().getIdentifier();
if (SqlTypes.TIME.getIdentifier().equals(logicalId)) {
return nullOr(
value, Expressions.divide(value, Expressions.constant(NANOS_PER_MILLISECOND)));
} else if (SqlTypes.DATE.getIdentifier().equals(logicalId)) {
return value;
} else if (SqlTypes.DATETIME.getIdentifier().equals(logicalId)) {
Expression dateValue =
Expressions.call(value, "getValue", Expressions.constant(DateTime.DATE_FIELD_NAME));
Expression timeValue =
Expressions.call(value, "getValue", Expressions.constant(DateTime.TIME_FIELD_NAME));
Expression returnValue =
Expressions.add(
Expressions.multiply(
Types.castIfNecessary(long.class, dateValue),
Expressions.constant(MILLIS_PER_DAY)),
Expressions.divide(
Types.castIfNecessary(long.class, timeValue),
Expressions.constant(NANOS_PER_MILLISECOND)));
return returnValue;
} else if (!CharType.IDENTIFIER.equals(logicalId)) {
throw new UnsupportedOperationException(
"Unknown LogicalType " + type.getLogicalType().getIdentifier());
}
} else if (type.getTypeName().isMapType()) {
return nullOr(value, map(value, type.getMapValueType()));
} else if (CalciteUtils.isDateTimeType(type)) {
return nullOr(value, Expressions.call(value, "getMillis"));
} else if (type.getTypeName().isCompositeType()) {
return nullOr(value, row(value, type.getRowSchema()));
} else if (type.getTypeName().isCollectionType()) {
return nullOr(value, list(value, type.getCollectionElementType()));
} else if (type.getTypeName() == TypeName.BYTES) {
return nullOr(
value, Expressions.new_(ByteString.class, Types.castIfNecessary(byte[].class, value)));
}
return value;
}

Line under review: Types.castIfNecessary(long.class, dateValue),

Code after addressing the review:
private static Expression value(Expression value, Schema.FieldType type) {
if (type.getTypeName().isLogicalType()) {
String logicalId = type.getLogicalType().getIdentifier();
if (SqlTypes.TIME.getIdentifier().equals(logicalId)) {
return nullOr(
value, Expressions.divide(value, Expressions.constant(NANOS_PER_MILLISECOND)));
} else if (SqlTypes.DATE.getIdentifier().equals(logicalId)) {
return value;
} else if (SqlTypes.DATETIME.getIdentifier().equals(logicalId)) {
Expression dateValue =
Expressions.call(value, "getInt64", Expressions.constant(DateTime.DATE_FIELD_NAME));
Expression timeValue =
Expressions.call(value, "getInt64", Expressions.constant(DateTime.TIME_FIELD_NAME));
Expression returnValue =
Expressions.add(
Expressions.multiply(dateValue, Expressions.constant(MILLIS_PER_DAY)),
Expressions.divide(timeValue, Expressions.constant(NANOS_PER_MILLISECOND)));
return nullOr(value, returnValue);
} else if (!CharType.IDENTIFIER.equals(logicalId)) {
throw new UnsupportedOperationException(
"Unknown LogicalType " + type.getLogicalType().getIdentifier());
}
} else if (type.getTypeName().isMapType()) {
return nullOr(value, map(value, type.getMapValueType()));
} else if (CalciteUtils.isDateTimeType(type)) {
return nullOr(value, Expressions.call(value, "getMillis"));
} else if (type.getTypeName().isCompositeType()) {
return nullOr(value, row(value, type.getRowSchema()));
} else if (type.getTypeName().isCollectionType()) {
return nullOr(value, list(value, type.getCollectionElementType()));
} else if (type.getTypeName() == TypeName.BYTES) {
return nullOr(
value, Expressions.new_(ByteString.class, Types.castIfNecessary(byte[].class, value)));
}
return value;
}