-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: standardize KSQL up-casting (#3516)
* fix: standardize KSQL up-casting Logic for controlling what types can be up-cast to another, e.g. up-casting an INT to a BIGINT was spread across different parts of the code base, had no tests to ensure all parts were consistent and hence was inconsistent. Up-casting is primarily used during arithmetic binary operations, e.g. adding two numbers together, and when trying to coerce user supplied values in `INSERT VALUE` statements to the required SQL types. Numeric Up-casting rules for KSQL are: - `INT` can be up-cast to `BIGINT` - `BIGINT` can be up-cast to `DECIMAL` - `DECIMAL` can be up-cast to `DOUBLE`. In the existing code: - `SqlBaseType` has a `canUpCast` method, but it doesn't take `DECIMAL`s into account. - `SqlBaseType` has an `isNumber` method, but it doesn't treat `DECIMAL` as a numeric type. - `SchemaUtil` has the logic on how to resolve the resulting (connect) schema given an `Operation` and two input types. - `DefaultSqlValueCoercer`, allowed coercion of `DOUBLE` -> `DECIMAL`, which is against out up-casting rules. This PR looks to make the code a bit more object orientated and hopefully better structured. With this change: - `SqlBaseType`'s `canUpCast` and `isNumber` methodss correctly handle `DECIMAL`. - Any type can be up-cast to itself. Only numeric types can be up-cast to other types and the rules are encapsulated in `SqlBaseType.canUpCast`. - The logic on how to resolve the resulting SQL type given an `Operation` and two input types now lives in `Operation`, making use of the decimal specific handling which now lives in `SqlDecimal`. - The `SqlDecimal` type an `INT` or `BIGINT` is up-cast to is now stored in `SqlTypes`. However, the main benefit of this commit is the addition of tests in `DefaultSqlValueCoercer` and `OperatorTest` to ensure that these two classes follow the up-casting rules.
- Loading branch information
1 parent
ed94895
commit 7fe8772
Showing
27 changed files
with
864 additions
and
598 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.