Skip to content

Commit

Permalink
Keep materialized view security overriden context until end of query
Browse files Browse the repository at this point in the history
  • Loading branch information
GrigoryPervakov committed Nov 7, 2024
1 parent 3efeccd commit a01c2e3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Processors/Sinks/SinkToStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace DB
{

class Context;

/// Sink which is returned from Storage::write.
class SinkToStorage : public ExceptionKeepingTransform
{
Expand All @@ -16,12 +18,14 @@ friend class PartitionedSink;

const Block & getHeader() const { return inputs.front().getHeader(); }
void addTableLock(const TableLockHolder & lock) { table_locks.push_back(lock); }
void addInterpreterContext(std::shared_ptr<const Context> context) { interpreter_context.emplace_back(std::move(context)); }

protected:
virtual void consume(Chunk & chunk) = 0;

private:
std::vector<TableLockHolder> table_locks;
std::vector<std::shared_ptr<const Context>> interpreter_context;

void onConsume(Chunk chunk) override;
GenerateResult onGenerate() override;
Expand Down
2 changes: 2 additions & 0 deletions src/Storages/StorageMaterializedView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ void StorageMaterializedView::read(
}

query_plan.addStorageHolder(storage);
query_plan.addInterpreterContext(context);
query_plan.addTableLock(std::move(lock));
}
}
Expand All @@ -405,6 +406,7 @@ SinkToStoragePtr StorageMaterializedView::write(const ASTPtr & query, const Stor

auto sink = storage->write(query, metadata_snapshot, context, async_insert);

sink->addInterpreterContext(context);
sink->addTableLock(lock);
return sink;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
DROP TABLE IF EXISTS {CLICKHOUSE_DATABASE:Identifier}.rview;
DROP TABLE IF EXISTS {CLICKHOUSE_DATABASE:Identifier}.wview;

-- Read from view
CREATE MATERIALIZED VIEW rview ENGINE = File(CSV) POPULATE AS SELECT 1 AS c0;
SELECT 1 FROM rview;

-- Write through view populate
CREATE MATERIALIZED VIEW wview ENGINE = Join(ALL, INNER, c0) POPULATE AS SELECT 1 AS c0;

0 comments on commit a01c2e3

Please sign in to comment.