Skip to content

Commit

Permalink
least/greatest function for string (pingcap#6662)
Browse files Browse the repository at this point in the history
  • Loading branch information
ywqzzy authored and guo-shaoge committed Feb 10, 2023
1 parent 93a4c11 commit a6daf46
Show file tree
Hide file tree
Showing 8 changed files with 1,014 additions and 28 deletions.
6 changes: 3 additions & 3 deletions dbms/src/Flash/Coprocessor/DAGUtils.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 PingCAP, Ltd.
// Copyright 2023 PingCAP, Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -162,13 +162,13 @@ const std::unordered_map<tipb::ScalarFuncSig, String> scalar_func_map({

{tipb::ScalarFuncSig::GreatestInt, "tidbGreatest"},
{tipb::ScalarFuncSig::GreatestReal, "tidbGreatest"},
{tipb::ScalarFuncSig::GreatestString, "greatest"},
{tipb::ScalarFuncSig::GreatestString, "tidbGreatestString"},
{tipb::ScalarFuncSig::GreatestDecimal, "greatest"},
{tipb::ScalarFuncSig::GreatestTime, "greatest"},

{tipb::ScalarFuncSig::LeastInt, "tidbLeast"},
{tipb::ScalarFuncSig::LeastReal, "tidbLeast"},
{tipb::ScalarFuncSig::LeastString, "least"},
{tipb::ScalarFuncSig::LeastString, "tidbLeastString"},
{tipb::ScalarFuncSig::LeastDecimal, "least"},
{tipb::ScalarFuncSig::LeastTime, "least"},

Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Functions/FunctionsComparison.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 PingCAP, Ltd.
// Copyright 2023 PingCAP, Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
18 changes: 9 additions & 9 deletions dbms/src/Functions/FunctionsConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ struct ConvertToDecimalImpl
}
else
{
if (const ColumnVector<FromFieldType> * col_from
if (const auto * col_from
= checkAndGetColumn<ColumnVector<FromFieldType>>(block.getByPosition(arguments[0]).column.get()))
{
auto col_to = ColumnDecimal<ToFieldType>::create(0, scale);
Expand Down Expand Up @@ -245,7 +245,7 @@ struct ConvertToDecimalImpl<DataTypeString, Name, ToDataType>

const IDataType & data_type_to = *block.getByPosition(result).type;

if (const ColumnString * col_from_string = checkAndGetColumn<ColumnString>(&col_from))
if (const auto * col_from_string = checkAndGetColumn<ColumnString>(&col_from))
{
auto res = data_type_to.createColumn();

Expand Down Expand Up @@ -758,8 +758,8 @@ struct ConvertThroughParsing
}

const IColumn * col_from = block.getByPosition(arguments[0]).column.get();
const ColumnString * col_from_string = checkAndGetColumn<ColumnString>(col_from);
const ColumnFixedString * col_from_fixed_string = checkAndGetColumn<ColumnFixedString>(col_from);
const auto * col_from_string = checkAndGetColumn<ColumnString>(col_from);
const auto * col_from_fixed_string = checkAndGetColumn<ColumnFixedString>(col_from);

if (std::is_same_v<FromDataType, DataTypeString> && !col_from_string)
throw Exception("Illegal column " + col_from->getName()
Expand Down Expand Up @@ -880,7 +880,7 @@ struct ConvertImplGenericFromString

const IDataType & data_type_to = *block.getByPosition(result).type;

if (const ColumnString * col_from_string = checkAndGetColumn<ColumnString>(&col_from))
if (const auto * col_from_string = checkAndGetColumn<ColumnString>(&col_from))
{
auto res = data_type_to.createColumn();

Expand Down Expand Up @@ -947,7 +947,7 @@ struct ConvertImpl<DataTypeFixedString, DataTypeString, Name>
{
static void execute(Block & block, const ColumnNumbers & arguments, size_t result)
{
if (const ColumnFixedString * col_from = checkAndGetColumn<ColumnFixedString>(block.getByPosition(arguments[0]).column.get()))
if (const auto * col_from = checkAndGetColumn<ColumnFixedString>(block.getByPosition(arguments[0]).column.get()))
{
auto col_to = ColumnString::create();

Expand Down Expand Up @@ -1754,7 +1754,7 @@ class FunctionDateFormat : public IFunction
class FunctionGetFormat : public IFunction
{
private:
static String get_format(const StringRef & time_type, const StringRef & location)
static String getFormat(const StringRef & time_type, const StringRef & location)
{
if (time_type == "DATE")
{
Expand Down Expand Up @@ -1850,7 +1850,7 @@ class FunctionGetFormat : public IFunction
for (size_t i = 0; i < size; ++i)
{
const auto & location = location_col->getDataAt(i);
const auto & result = get_format(StringRef(time_type), location);
const auto & result = getFormat(StringRef(time_type), location);
write_buffer.write(result.c_str(), result.size());
writeChar(0, write_buffer);
offsets_to[i] = write_buffer.count();
Expand Down Expand Up @@ -2615,7 +2615,7 @@ class FunctionCast final : public IFunctionBase
const size_t result) {
const auto & array_arg = block.getByPosition(arguments.front());

if (const ColumnArray * col_array = checkAndGetColumn<ColumnArray>(array_arg.column.get()))
if (const auto * col_array = checkAndGetColumn<ColumnArray>(array_arg.column.get()))
{
/// create block for converting nested column containing original and result columns
Block nested_block{
Expand Down
Loading

0 comments on commit a6daf46

Please sign in to comment.