2022-06-10 08:22:31 +00:00
|
|
|
#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>
|
2019-07-23 12:46:58 +00:00
|
|
|
#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>
|
2021-10-31 08:51:20 +00:00
|
|
|
#include <Access/Common/AccessFlags.h>
|
2019-07-29 23:54:49 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2019-02-10 03:10:07 +00:00
|
|
|
#include <IO/WriteHelpers.h>
|
|
|
|
|
2019-07-23 12:46:58 +00:00
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
2019-07-29 23:49:00 +00:00
|
|
|
class FunctionAddressToSymbol : public IFunction
|
2019-02-10 03:10:07 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-07-29 23:49:00 +00:00
|
|
|
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
|
|
|
{
|
2021-04-10 23:33:54 +00:00
|
|
|
context->checkAccess(AccessType::addressToSymbol);
|
2019-07-29 23:49:00 +00:00
|
|
|
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; }
|
2021-04-29 14:48:26 +00:00
|
|
|
|
2019-02-10 03:10:07 +00:00
|
|
|
DataTypePtr getReturnTypeImpl(const ColumnsWithTypeAndName & arguments) const override
|
|
|
|
{
|
|
|
|
if (arguments.size() != 1)
|
2023-01-23 21:13:58 +00:00
|
|
|
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
|
|
|
|
2019-07-23 12:46:58 +00:00
|
|
|
const auto & type = arguments[0].type;
|
2019-02-10 03:10:07 +00:00
|
|
|
|
2019-07-23 12:46:58 +00:00
|
|
|
if (!WhichDataType(type.get()).isUInt64())
|
2023-01-23 21:13:58 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-11-17 13:24:45 +00:00
|
|
|
ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr &, size_t input_rows_count) const override
|
2019-02-10 03:10:07 +00:00
|
|
|
{
|
2023-07-09 07:20:03 +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;
|
2019-07-23 12:46:58 +00:00
|
|
|
const ColumnUInt64 * column_concrete = checkAndGetColumn<ColumnUInt64>(column.get());
|
2019-02-10 03:10:07 +00:00
|
|
|
|
2019-07-23 12:46:58 +00:00
|
|
|
if (!column_concrete)
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Illegal column {} of argument of function {}", column->getName(), getName());
|
2019-02-10 03:10:07 +00:00
|
|
|
|
2019-07-23 12:46:58 +00:00
|
|
|
const typename ColumnVector<UInt64>::Container & data = column_concrete->getData();
|
2019-02-10 03:10:07 +00:00
|
|
|
auto result_column = ColumnString::create();
|
|
|
|
|
2019-07-23 12:46:58 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-07-04 07:01:39 +00:00
|
|
|
REGISTER_FUNCTION(AddressToSymbol)
|
2019-07-23 12:55:13 +00:00
|
|
|
{
|
2019-07-29 23:49:00 +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
|