ClickHouse/src/Functions/addressToSymbol.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

104 lines
2.9 KiB
C++
Raw Normal View History

#if defined(__ELF__) && !defined(OS_FREEBSD)
2019-08-21 00:48:34 +00:00
2019-07-29 01:08:52 +00:00
#include <Common/SymbolIndex.h>
2019-02-10 03:10:07 +00:00
#include <Columns/ColumnString.h>
#include <Columns/ColumnsNumber.h>
2019-02-10 03:10:07 +00:00
#include <DataTypes/DataTypeString.h>
2021-05-17 07:30:42 +00:00
#include <Functions/IFunction.h>
2019-07-23 12:55:13 +00:00
#include <Functions/FunctionFactory.h>
#include <Access/Common/AccessFlags.h>
#include <Interpreters/Context.h>
2019-02-10 03:10:07 +00:00
#include <IO/WriteHelpers.h>
2019-02-10 03:10:07 +00:00
namespace DB
{
namespace ErrorCodes
{
extern const int ILLEGAL_COLUMN;
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
}
2020-09-07 18:00:37 +00:00
namespace
{
class FunctionAddressToSymbol : public IFunction
2019-02-10 03:10:07 +00:00
{
public:
static constexpr auto name = "addressToSymbol";
2021-06-01 12:20:52 +00:00
static FunctionPtr create(ContextPtr context)
2019-02-10 03:10:07 +00:00
{
context->checkAccess(AccessType::addressToSymbol);
return std::make_shared<FunctionAddressToSymbol>();
2019-02-10 03:10:07 +00:00
}
String getName() const override
{
return name;
}
size_t getNumberOfArguments() const override
{
return 1;
}
2021-06-22 16:21:23 +00:00
bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override { return true; }
2019-02-10 03:10:07 +00:00
DataTypePtr getReturnTypeImpl(const ColumnsWithTypeAndName & arguments) const override
{
if (arguments.size() != 1)
throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, "Function {} needs exactly one argument; passed {}.",
getName(), arguments.size());
2019-02-10 03:10:07 +00:00
const auto & type = arguments[0].type;
2019-02-10 03:10:07 +00:00
if (!WhichDataType(type.get()).isUInt64())
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "The only argument for function {} must be UInt64. "
"Found {} instead.", getName(), type->getName());
2019-02-10 03:10:07 +00:00
return std::make_shared<DataTypeString>();
}
bool useDefaultImplementationForConstants() const override
{
return true;
}
ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr &, size_t input_rows_count) const override
2019-02-10 03:10:07 +00:00
{
const SymbolIndex & symbol_index = SymbolIndex::instance();
2019-07-29 01:08:52 +00:00
2020-10-17 15:22:42 +00:00
const ColumnPtr & column = arguments[0].column;
const ColumnUInt64 * column_concrete = checkAndGetColumn<ColumnUInt64>(column.get());
2019-02-10 03:10:07 +00:00
if (!column_concrete)
throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Illegal column {} of argument of function {}", column->getName(), getName());
2019-02-10 03:10:07 +00:00
const typename ColumnVector<UInt64>::Container & data = column_concrete->getData();
2019-02-10 03:10:07 +00:00
auto result_column = ColumnString::create();
for (size_t i = 0; i < input_rows_count; ++i)
2019-02-10 03:10:07 +00:00
{
2019-07-29 18:38:04 +00:00
if (const auto * symbol = symbol_index.findSymbol(reinterpret_cast<const void *>(data[i])))
2022-09-17 03:34:18 +00:00
result_column->insertData(symbol->name, strlen(symbol->name));
2019-07-29 01:08:52 +00:00
else
result_column->insertDefault();
2019-02-10 03:10:07 +00:00
}
2020-10-17 15:22:42 +00:00
return result_column;
2019-02-10 03:10:07 +00:00
}
};
2020-09-07 18:00:37 +00:00
}
REGISTER_FUNCTION(AddressToSymbol)
2019-07-23 12:55:13 +00:00
{
factory.registerFunction<FunctionAddressToSymbol>();
2019-07-23 12:55:13 +00:00
}
2019-02-10 03:10:07 +00:00
}
2019-08-21 00:48:34 +00:00
#endif