As a Master Thesis I need to expand the database duckdb on github with functionality.
One of the first steps was to create a fixed internal plan that represents something like "select 42;" just on physical level. To that end I tired to manually create such a plan with the classes used internally by duckdb.
On compiling I generally get an error message like this:
/home/ubuntu/git/duckdb/src/include/common/helper.hpp: In instantiation of ‘std::unique_ptr<T> duckdb::make_unique(Args&& ...)
[with T = duckdb::Expression; Args = {duckdb::ExpressionType,
duckdb::ExpressionClass, duckdb::TypeId}]’:
/home/ubuntu/git/duckdb/src/execution/physical_plan_generator.cpp:125:155:
required from here
/home/ubuntu/git/duckdb/src/include/common/helper.hpp:24:23: error:
invalid new-expression of abstract class type ‘duckdb::Expression’
return unique_ptr<T>(new T(std::forward<Args>(args)...));
The creation was this line:
unique_ptr<Expression> ProjectionExpression = make_unique<Expression>(ExpressionType::VALUE_CONSTANT, ExpressionClass::BOUND_CONSTANT, TypeId::INTEGER);
The constructor is
Expression::Expression(ExpressionType type, ExpressionClass expression_class, TypeId return_type)
: BaseExpression(type, expression_class), return_type(return_type) {
}
with baseexpression being
BaseExpression(ExpressionType type, ExpressionClass expression_class)
: type(type), expression_class(expression_class) {
}
virtual ~BaseExpression() {
}
As you can see the class expression uses an initialization list from class baseExpression. As Far as I can tell there is no direct inheritance between the 2 but clearly I need something that is currently missing to correctly initialize the constructor.
The problem is that normally in duckdb these things come from the parser and get then built from these objects. And I have to try and guess how the data structure is supposed to look like.
I am having problems figuring out how to directly allocate this object with make_unique because expression clearly requires a baseExpression of somekind but baseexpression itself has a virtual component so I can't just create that one directly either.
basically what I am asking is: How do you make a new unique_ptr object when the class is abstract?