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>
|
|
|
|
#include <Functions/IFunction.h>
|
|
|
|
#include <Functions/FunctionHelpers.h>
|
2019-07-23 12:55:13 +00:00
|
|
|
#include <Functions/FunctionFactory.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 SIZES_OF_ARRAYS_DOESNT_MATCH;
|
|
|
|
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
|
|
|
|
}
|
|
|
|
|
2019-07-23 12:46:58 +00:00
|
|
|
class FunctionSymbolizeAddress : public IFunction
|
2019-02-10 03:10:07 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-07-23 12:46:58 +00:00
|
|
|
static constexpr auto name = "symbolizeAddress";
|
2019-02-10 03:10:07 +00:00
|
|
|
static FunctionPtr create(const Context &)
|
|
|
|
{
|
2019-07-23 12:46:58 +00:00
|
|
|
return std::make_shared<FunctionSymbolizeAddress>();
|
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;
|
|
|
|
}
|
|
|
|
|
2019-07-23 12:46:58 +00:00
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result, size_t input_rows_count) override
|
2019-02-10 03:10:07 +00:00
|
|
|
{
|
2019-07-29 01:08:52 +00:00
|
|
|
static SymbolIndex symbol_index;
|
|
|
|
|
2019-07-23 12:46:58 +00:00
|
|
|
const ColumnPtr & column = block.getByPosition(arguments[0]).column;
|
|
|
|
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 01:08:52 +00:00
|
|
|
result_column->insertDataWithTerminatingZero(symbol->name.data(), symbol->name.size() + 1);
|
|
|
|
else
|
|
|
|
result_column->insertDefault();
|
2019-02-10 03:10:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
block.getByPosition(result).column = std::move(result_column);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-07-23 12:55:13 +00:00
|
|
|
void registerFunctionSymbolizeAddress(FunctionFactory & factory)
|
|
|
|
{
|
|
|
|
factory.registerFunction<FunctionSymbolizeAddress>();
|
|
|
|
}
|
|
|
|
|
2019-02-10 03:10:07 +00:00
|
|
|
}
|