Skip to content

Commit

Permalink
Fix mismatched return type of EXTRACT (#1643) (#1650)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-srebot authored Mar 25, 2021
1 parent a41eab2 commit c70e0ed
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
1 change: 0 additions & 1 deletion dbms/src/DataTypes/DataTypeMyDate.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class DataTypeMyDate final : public DataTypeMyTimeBase
void deserializeTextCSV(IColumn & column, ReadBuffer & istr, const char delimiter) const override;

bool canBeUsedAsVersion() const override { return true; }
bool isDateOrDateTime() const override { return true; }
bool canBeInsideNullable() const override { return true; }

bool equals(const IDataType & rhs) const override;
Expand Down
1 change: 1 addition & 0 deletions dbms/src/DataTypes/DataTypeMyTimeBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class DataTypeMyTimeBase : public DataTypeNumberBase<UInt64>
public:
bool canBeUsedAsVersion() const override { return true; }
bool isDateOrDateTime() const override { return true; }
bool isMyDateOrMyDateTime() const override { return true; }
bool canBeInsideNullable() const override { return true; }
};

Expand Down
4 changes: 4 additions & 0 deletions dbms/src/DataTypes/IDataType.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,10 @@ class IDataType : private boost::noncopyable
*/
virtual bool isDateOrDateTime() const { return false; };

/** MyDate, MyDateTime. Not Nullable.
*/
virtual bool isMyDateOrMyDateTime() const { return false; };

/** Decimal. Not Nullable.
*/
virtual bool isDecimal() const { return false; };
Expand Down
11 changes: 2 additions & 9 deletions dbms/src/Functions/FunctionsDateTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -2384,12 +2384,12 @@ class FunctionExtractMyDateTime : public IFunction

// TODO: Support Extract from string, see https://github.com/pingcap/tidb/issues/22700
// if (!(arguments[1]->isString() || arguments[1]->isDateOrDateTime()))
if (!arguments[1]->isDateOrDateTime())
if (!arguments[1]->isMyDateOrMyDateTime())
throw TiFlashException(
"Illegal type " + arguments[1]->getName() + " of second argument of function " + getName() + ". Must be DateOrDateTime.",
Errors::Coprocessor::BadRequest);

return std::make_shared<DataTypeNullable>(std::make_shared<DataTypeInt64>());
return std::make_shared<DataTypeInt64>();
}

bool useDefaultImplementationForConstants() const override { return true; }
Expand All @@ -2406,13 +2406,6 @@ class FunctionExtractMyDateTime : public IFunction

auto from_column = block.getByPosition(arguments[1]).column;


if (from_column->onlyNull())
{
block.getByPosition(result).column = block.getByPosition(result).type->createColumnConst(block.rows(), Null());
return;
}

size_t rows = block.rows();
auto col_to = ColumnInt64::create(rows);
auto & vec_to = col_to->getData();
Expand Down

0 comments on commit c70e0ed

Please sign in to comment.