Skip to content

Commit

Permalink
[fix](planner) insert default value should not change return type of …
Browse files Browse the repository at this point in the history
…function object in function set (apache#17536)

function now's return type changed to datetimev2 by mistake.
It can be reproduced in the following way

CREATE TABLE `testdt` (
  `c1` int(11) NULL,
  `c2` datetimev2 NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=OLAP
DUPLICATE KEY(`c1`, `c2`)
COMMENT 'OLAP'
DISTRIBUTED BY HASH(`c1`) BUCKETS 10
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"in_memory" = "false",
"storage_format" = "V2",
"light_schema_change" = "true",
"disable_auto_compaction" = "false"
);

 insert into testdt2(c1) values(1);

select now();
  • Loading branch information
morrySnow authored Mar 8, 2023
1 parent b1ca87e commit 678f34c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,8 @@ protected String getFunctionNotFoundError(Type[] argTypes) {
* @throws AnalysisException
*/
public void analyzeImplForDefaultValue(Type type) throws AnalysisException {
fn = getBuiltinFunction(fnName.getFunction(), new Type[0], Function.CompareMode.IS_NONSTRICT_SUPERTYPE_OF);
fn = new Function(getBuiltinFunction(fnName.getFunction(), new Type[0],
Function.CompareMode.IS_NONSTRICT_SUPERTYPE_OF));
fn.setReturnType(type);
this.type = type;
for (int i = 0; i < children.size(); ++i) {
Expand Down
20 changes: 20 additions & 0 deletions fe/fe-core/src/main/java/org/apache/doris/catalog/Function.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,26 @@ public Function(long id, FunctionName name, List<Type> argTypes, Type retType,
this(id, name, argTypes, retType, hasVarArgs, TFunctionBinaryType.BUILTIN, true, vectorized, mode);
}

public Function(Function other) {
if (other == null) {
return;
}
this.id = other.id;
this.name = new FunctionName(other.name.getDb(), other.name.getFunction());
this.hasVarArgs = other.hasVarArgs;
this.retType = other.retType;
this.userVisible = other.userVisible;
this.nullableMode = other.nullableMode;
this.vectorized = other.vectorized;
this.binaryType = other.binaryType;
this.location = other.location;
if (other.argTypes != null) {
this.argTypes = new Type[other.argTypes.length];
System.arraycopy(other.argTypes, 0, this.argTypes, 0, other.argTypes.length);
}
this.checksum = other.checksum;
}

public FunctionName getFunctionName() {
return name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ suite("test_current_timestamp") {
qt_insert_into """ select count(*) from ${tableName} where to_date(dt_4) = to_date(dt_5); """
qt_insert_into """ select count(*) from ${tableName} where to_date(dt_6) = to_date(dt_7); """

sql """select now()"""

// test stream load.
streamLoad {
table "${tableName}"
Expand All @@ -64,4 +66,6 @@ suite("test_current_timestamp") {
qt_stream_load """ select count(*) from ${tableName} where id > 4 and to_date(dt_2) = to_date(dt_3); """
qt_stream_load """ select count(*) from ${tableName} where id > 4 and to_date(dt_4) = to_date(dt_5); """
qt_stream_load """ select count(*) from ${tableName} where id > 4 and to_date(dt_6) = to_date(dt_7); """

sql """select now()"""
}

0 comments on commit 678f34c

Please sign in to comment.