Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
zclllyybb committed Sep 26, 2023
1 parent 504ab2d commit f27a415
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 27 deletions.
25 changes: 5 additions & 20 deletions be/src/vec/functions/function_timestamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ struct StrToDate {
static DataTypes get_variadic_argument_types() { return {}; }

static DataTypePtr get_return_type_impl(const DataTypes& arguments) {
return make_nullable(std::make_shared<DataTypeDateTime>());
//TODO: it doesn't matter now. maybe sometime we should find the function signature with return_type together
return make_nullable(std::make_shared<DataTypeDateV2>());
}

static StringRef rewrite_specific_format(const char* raw_str, size_t str_size) {
Expand Down Expand Up @@ -115,6 +116,8 @@ struct StrToDate {
auto& rdata = specific_char_column->get_chars();
auto& roffsets = specific_char_column->get_offsets();

// Because of we cant distinguish by return_type when we find function. so the return_type may NOT be same with real return type
// which decided by FE. that's found by which.
ColumnPtr res = nullptr;
WhichDataType which(remove_nullable(block.get_by_position(result).type));
if (which.is_date_time_v2()) {
Expand Down Expand Up @@ -144,18 +147,7 @@ struct StrToDate {
null_map->get_data());
}
} else {
res = ColumnVector<Int64>::create();
if (col_const[1]) {
execute_impl_const_right<VecDateTimeValue, Int64>(
context, ldata, loffsets, specific_char_column->get_data_at(0),
static_cast<ColumnVector<Int64>*>(res->assume_mutable().get())->get_data(),
null_map->get_data());
} else {
execute_impl<VecDateTimeValue, Int64>(
context, ldata, loffsets, rdata, roffsets,
static_cast<ColumnVector<Int64>*>(res->assume_mutable().get())->get_data(),
null_map->get_data());
}
DCHECK(false);
}

block.get_by_position(result).column = ColumnNullable::create(res, std::move(null_map));
Expand Down Expand Up @@ -209,13 +201,6 @@ struct StrToDate {
if (!ts_val.from_date_format_str(r_raw_str, r_str_size, l_raw_str, l_str_size)) {
null_map[index] = 1;
}
if constexpr (std::is_same_v<DateValueType, VecDateTimeValue>) {
if (context->get_return_type().type == doris::PrimitiveType::TYPE_DATETIME) {
ts_val.to_datetime();
} else {
ts_val.cast_to_date();
}
}
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.DataType;
import org.apache.doris.nereids.types.DateTimeType;
import org.apache.doris.nereids.types.DateTimeV2Type;
import org.apache.doris.nereids.types.StringType;
import org.apache.doris.nereids.types.VarcharType;

Expand All @@ -44,8 +44,9 @@ public class StrToDate extends ScalarFunction
implements BinaryExpression, ExplicitlyCastableSignature, AlwaysNullable {

public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(DateTimeType.INSTANCE).args(VarcharType.SYSTEM_DEFAULT, VarcharType.SYSTEM_DEFAULT),
FunctionSignature.ret(DateTimeType.INSTANCE).args(StringType.INSTANCE, StringType.INSTANCE)
FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT).args(VarcharType.SYSTEM_DEFAULT,
VarcharType.SYSTEM_DEFAULT),
FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT).args(StringType.INSTANCE, StringType.INSTANCE)
);

/**
Expand Down Expand Up @@ -86,6 +87,9 @@ public FunctionSignature computeSignature(FunctionSignature signature) {
if (getArgument(1) instanceof StringLikeLiteral) {
if (DateLiteral.hasTimePart(((StringLikeLiteral) getArgument(1)).getStringValue())) {
returnType = DataType.fromCatalogType(ScalarType.getDefaultDateType(Type.DATETIME));
if (returnType.isDateTimeV2Type()) {
returnType = DataType.fromCatalogType(Type.DATETIMEV2_WITH_MAX_SCALAR);
}
} else {
returnType = DataType.fromCatalogType(ScalarType.getDefaultDateType(Type.DATE));
}
Expand Down
6 changes: 4 additions & 2 deletions gensrc/script/doris_builtins_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,8 +939,10 @@
[['datediff'], 'INT', ['DATETIME', 'DATETIME'], 'ALWAYS_NULLABLE'],
[['timediff'], 'TIME', ['DATETIME', 'DATETIME'], 'ALWAYS_NULLABLE'],

[['str_to_date'], 'DATETIME', ['VARCHAR', 'VARCHAR'], 'ALWAYS_NULLABLE'],
[['str_to_date'], 'DATETIME', ['STRING', 'STRING'], 'ALWAYS_NULLABLE'],
[['str_to_date'], 'DATETIMEV2', ['VARCHAR', 'VARCHAR'], 'ALWAYS_NULLABLE'],
[['str_to_date'], 'DATETIMEV2', ['STRING', 'STRING'], 'ALWAYS_NULLABLE'],
[['str_to_date'], 'DATEV2', ['VARCHAR', 'VARCHAR'], 'ALWAYS_NULLABLE'],
[['str_to_date'], 'DATEV2', ['STRING', 'STRING'], 'ALWAYS_NULLABLE'],
[['date_format'], 'VARCHAR', ['DATETIME', 'VARCHAR'], 'ALWAYS_NULLABLE'],
[['date_format'], 'VARCHAR', ['DATE', 'VARCHAR'], 'ALWAYS_NULLABLE'],
[['date', 'to_date'], 'DATE', ['DATETIME'], 'ALWAYS_NULLABLE'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ February
2014-12-21T12:34:56

-- !sql --
2014-12-21T12:34:56
2014-12-21T12:34:56.000789

-- !sql --
2004-10-18
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ February
2014-12-21T12:34:56

-- !sql --
2014-12-21T12:34:56
2014-12-21T12:34:56.000789

-- !sql --
2004-10-18
Expand Down

0 comments on commit f27a415

Please sign in to comment.