Skip to content

Commit cc5bb30

Browse files
committed
generate pragma queries programmatically
1 parent 7c04dce commit cc5bb30

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

include/ivm_rewrite_rule.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ class IVMRewriteRule : public OptimizerExtension {
4141
// create insert node. It is new node, hence it gets a new table_idx
4242
auto insert_node = make_uniq<LogicalInsert>(*table, table_index += 1);
4343

44-
// generate bindings for the insert node using the child node
45-
auto plan_top_node = plan.get();
44+
// generate bindings for the insert node using the top node of the plan
4645
Value value;
4746
unique_ptr<BoundConstantExpression> exp;
4847
for (int i=0;i<plan->expressions.size();i++) {

ivm_extension.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,16 @@ static void DoIVMFunction(ClientContext &context, TableFunctionInput &data_p, Da
9393
}
9494

9595
string UpsertDeltaQueries(ClientContext &context, const FunctionParameters &parameters) {
96-
printf("In pragma call\n");
96+
string view_catalog_name = StringValue::Get(parameters.values[0]);
97+
string view_schema_name = StringValue::Get(parameters.values[1]);
98+
string view_name = StringValue::Get(parameters.values[2]);
99+
100+
string query_create_view_delta_table = "CREATE TABLE delta_"+view_name+" AS (SELECT * FROM "+view_name+" LIMIT 0);";
101+
string query_add_multiplicity_col = "ALTER TABLE delta_"+view_name+" ADD COLUMN _duckdb_ivm_multiplicity BOOL;";
102+
string ivm_query = "SELECT * from DoIVM('"+view_catalog_name+"','"+view_schema_name+"','"+view_name+"');";
103+
string select_query = "SELECT * FROM delta_"+view_name+";";
104+
string query = query_create_view_delta_table + query_add_multiplicity_col + ivm_query + select_query;
105+
return query;
97106
return "create table delta_test as (select * from test limit 0); alter table delta_test add column _duckdb_ivm_multiplicity bool; insert into delta_test select * from DoIVM('memory', 's', 'test'); SELECT * FROM delta_test; ";
98107
}
99108

@@ -122,7 +131,8 @@ static void LoadInternal(DatabaseInstance &instance) {
122131
catalog.CreateTableFunction(*con.context, &ivm_func_info);
123132
con.Commit();
124133

125-
auto upsert_delta_func = PragmaFunction::PragmaCall("upsert_delta", UpsertDeltaQueries, {});
134+
auto upsert_delta_func = PragmaFunction::PragmaCall("ivm_upsert", UpsertDeltaQueries,
135+
{LogicalType::VARCHAR, LogicalType::VARCHAR, LogicalType::VARCHAR});
126136
ExtensionUtil::RegisterFunction(instance, upsert_delta_func);
127137
}
128138

0 commit comments

Comments
 (0)