[Fix](type) fix wrong type transform for unix_timestamp (#27728)

fix wrong type transform for unix_timestamp
This commit is contained in:
zclllyybb
2023-12-01 09:58:20 +08:00
committed by GitHub
parent c1d73ecefb
commit 2afbece0b8
4 changed files with 17 additions and 18 deletions

View File

@ -1693,11 +1693,9 @@ public class FunctionCallExpr extends Expr {
type.getScalarScale()));
} else if (getChild(0).type.isStringType()) {
// use DATETIME to make scale adaptive
ScalarType type = ((ScalarType) (((StringLiteral) getChild(0))
.uncheckedCastTo(ScalarType.DATETIME).type));
ScalarType type = ((ScalarType) (getChild(0).uncheckedCastTo(ScalarType.DATETIME).type));
if (type.isDatetimeV2()) {
int scale = ((ScalarType) (((StringLiteral) getChild(0))
.uncheckedCastTo(ScalarType.DATETIME).type)).getScalarScale();
int scale = type.getScalarScale();
fn.setReturnType(
ScalarType.createDecimalType(PrimitiveType.DECIMAL64, 10 + scale, scale));
}

View File

@ -83,8 +83,8 @@ public class UnixTimestamp extends ScalarFunction
* [['unix_timestamp'], 'INT', ['DATE'], 'DEPEND_ON_ARGUMENT'],
* [['unix_timestamp'], 'DECIMAL64', ['DATETIMEV2'], 'DEPEND_ON_ARGUMENT'],
* [['unix_timestamp'], 'INT', ['DATEV2'], 'DEPEND_ON_ARGUMENT'],
* [['unix_timestamp'], 'INT', ['VARCHAR', 'VARCHAR'], 'ALWAYS_NULLABLE'],
* [['unix_timestamp'], 'INT', ['STRING', 'STRING'], 'ALWAYS_NULLABLE'],
* [['unix_timestamp'], 'DECIMAL64', ['VARCHAR', 'VARCHAR'], 'ALWAYS_NULLABLE'],
* [['unix_timestamp'], 'DECIMAL64', ['STRING', 'STRING'], 'ALWAYS_NULLABLE'],
*/
@Override
public boolean nullable() {