2019-10-05 19:25:31 +00:00
|
|
|
#if defined(__ELF__) && !defined(__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>
|
2019-12-09 13:12:54 +00:00
|
|
|
#include <Functions/IFunctionImpl.h>
|
2019-07-23 12:55:13 +00:00
|
|
|
#include <Functions/FunctionFactory.h>
|
2020-01-26 09:49:53 +00:00
|
|
|
#include <Access/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";
|
2019-07-29 23:54:49 +00:00
|
|
|
static FunctionPtr create(const Context & context)
|
2019-02-10 03:10:07 +00:00
|
|
|
{
|
2020-01-24 16:20:36 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
DataTypePtr getReturnTypeImpl(const ColumnsWithTypeAndName & arguments) const override
|
|
|
|
{
|
|
|
|
if (arguments.size() != 1)
|
|
|
|
throw Exception("Function " + getName() + " needs exactly one argument; passed "
|
2019-07-23 12:46:58 +00:00
|
|
|
+ toString(arguments.size()) + ".", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
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())
|
|
|
|
throw Exception("The only argument for function " + getName() + " must be UInt64. Found "
|
|
|
|
+ type->getName() + " instead.", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
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
|
|
|
{
|
2020-11-30 14:30:55 +00:00
|
|
|
auto symbol_index_ptr = SymbolIndex::instance();
|
|
|
|
const SymbolIndex & symbol_index = *symbol_index_ptr;
|
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)
|
|
|
|
throw Exception("Illegal column " + column->getName() + " of argument of function " + getName(), ErrorCodes::ILLEGAL_COLUMN);
|
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])))
|
2019-07-29 22:26:44 +00:00
|
|
|
result_column->insertDataWithTerminatingZero(symbol->name, strlen(symbol->name) + 1);
|
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
|
|
|
}
|
|
|
|
|
2019-07-29 23:49:00 +00:00
|
|
|
void registerFunctionAddressToSymbol(FunctionFactory & factory)
|
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
|