ClickHouse/src/Functions/wkt.cpp

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

83 lines
2.0 KiB
C++
Raw Normal View History

2021-02-19 18:09:38 +00:00
#include <DataTypes/DataTypeString.h>
#include <Functions/FunctionFactory.h>
#include <Functions/geometryConverters.h>
#include <Columns/ColumnString.h>
2020-06-07 16:04:35 +00:00
2021-02-19 18:09:38 +00:00
#include <string>
#include <memory>
2020-06-07 16:04:35 +00:00
2021-02-19 18:09:38 +00:00
namespace DB
{
2020-06-07 16:04:35 +00:00
2023-10-30 02:20:04 +00:00
namespace
{
2021-02-19 18:09:38 +00:00
class FunctionWkt : public IFunction
{
public:
static inline const char * name = "wkt";
2020-06-07 16:04:35 +00:00
2021-02-19 18:09:38 +00:00
explicit FunctionWkt() = default;
2020-06-07 16:04:35 +00:00
2021-06-01 12:20:52 +00:00
static FunctionPtr create(ContextPtr)
2021-02-19 18:09:38 +00:00
{
return std::make_shared<FunctionWkt>();
}
2020-06-07 16:04:35 +00:00
2021-02-19 18:09:38 +00:00
String getName() const override
{
return name;
}
2020-06-07 16:04:35 +00:00
2021-02-19 18:09:38 +00:00
size_t getNumberOfArguments() const override
{
return 1;
}
2020-06-07 16:04:35 +00:00
2021-02-19 18:09:38 +00:00
DataTypePtr getReturnTypeImpl(const DataTypes &) const override
{
return std::make_shared<DataTypeString>();
}
2020-06-07 16:04:35 +00:00
2021-06-22 16:21:23 +00:00
bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override { return true; }
2021-02-19 18:09:38 +00:00
ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & /*result_type*/, size_t input_rows_count) const override
{
auto res_column = ColumnString::create();
2020-06-07 16:04:35 +00:00
callOnGeometryDataType<CartesianPoint>(arguments[0].type, [&] (const auto & type)
2021-02-19 18:09:38 +00:00
{
2021-02-20 13:59:37 +00:00
using TypeConverter = std::decay_t<decltype(type)>;
using Converter = typename TypeConverter::Type;
2021-02-20 17:44:18 +00:00
2021-02-26 15:29:26 +00:00
auto figures = Converter::convert(arguments[0].column->convertToFullColumnIfConst());
2020-06-07 16:04:35 +00:00
2021-12-20 12:55:07 +00:00
for (size_t i = 0; i < input_rows_count; ++i)
{
std::stringstream str; // STYLE_CHECK_ALLOW_STD_STRING_STREAM
2023-10-30 02:20:04 +00:00
str.exceptions(std::ios::failbit);
str << boost::geometry::wkt(figures[i]);
std::string serialized = str.str();
res_column->insertData(serialized.c_str(), serialized.size());
}
}
);
2021-02-20 13:59:37 +00:00
2021-02-19 18:09:38 +00:00
return res_column;
}
2020-06-07 17:28:05 +00:00
2021-02-19 18:09:38 +00:00
bool useDefaultImplementationForConstants() const override
{
return true;
}
};
2020-06-07 16:04:35 +00:00
2023-10-30 02:20:04 +00:00
}
REGISTER_FUNCTION(Wkt)
2021-02-19 18:09:38 +00:00
{
factory.registerFunction<FunctionWkt>();
}
2020-06-07 16:04:35 +00:00
2021-02-19 18:09:38 +00:00
}