Skip to content

CLIENT-4533 Change asInt() and asFloat() to always generate casting Exp#68

Merged
agrgr merged 8 commits intomainfrom
CLIENT-4533-update-casting
Mar 27, 2026
Merged

CLIENT-4533 Change asInt() and asFloat() to always generate casting Exp#68
agrgr merged 8 commits intomainfrom
CLIENT-4533-update-casting

Conversation

@agrgr
Copy link
Copy Markdown
Collaborator

@agrgr agrgr commented Mar 27, 2026

No description provided.

@agrgr agrgr requested a review from tim-aero March 27, 2026 16:51
@agrgr agrgr added the enhancement New feature or request label Mar 27, 2026
@agrgr agrgr marked this pull request as ready for review March 27, 2026 17:10
Comment on lines +30 to +35
private Exp valueToExp() {
if (value instanceof Boolean b) return Exp.val(b);
if (value instanceof String s) return Exp.val(s);
if (value instanceof Float f) return Exp.val(f);
return Exp.val((Integer) value);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can "value" be other types, like Long, Double, byte[], primitive types, etc? If so, we should make this method more flexible

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently no, but this implementation is somewhat fragile, and there will be support for more types in future, so updating.

Comment on lines +30 to +35
private Exp valueToExp() {
if (value instanceof Boolean b) return Exp.val(b);
if (value instanceof String s) return Exp.val(s);
if (value instanceof Float f) return Exp.val(f);
return Exp.val((Integer) value);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make one of these methods static and possibly in a helper class rather than violating the DRY principle?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree

Comment on lines +31 to +39
case INT -> Exp.Type.FLOAT;
case FLOAT -> Exp.Type.INT;
};
}

public static ExprPartsOperation castTypeToOperation(CastType castType) {
return switch (castType) {
case INT -> ExprPartsOperation.TO_INT;
case FLOAT -> ExprPartsOperation.TO_FLOAT;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These methods both start with "cast" so I assume they have a similar function. Yet one maps INT -> INT, the other INT -> FLOAT. Is this deliberate or is one of the methods backwards? If so I would add a comment in to explain why.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually deliberate. The inverse mapping in castSourceExpType exists because when toInt() is used, the bin must be read with Exp.Type.FLOAT (its actual type) before the cast converts it to INT, it can be seen in PathOperandUtils.processValueType():56-59.
You are right that this can be confusing. The name castSourceExpType doesn't immediately convey "inverse of target". Adding a comment.

@agrgr agrgr requested a review from tim-aero March 27, 2026 18:57
@agrgr agrgr merged commit 765f52e into main Mar 27, 2026
12 checks passed
@agrgr agrgr deleted the CLIENT-4533-update-casting branch March 27, 2026 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants