-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix: format schema cache is not cleared after the schema is dropped (
#781)
- Loading branch information
1 parent
4588e5c
commit 2b723fb
Showing
13 changed files
with
199 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,59 @@ | ||
#pragma once | ||
|
||
#include "Formats/FormatSettings.h" | ||
#include "IO/ReadBuffer.h" | ||
#include <Formats/FormatSchemaInfo.h> | ||
#include <Formats/FormatSettings.h> | ||
#include <IO/WriteBufferFromFile.h> | ||
|
||
#include <filesystem> | ||
|
||
namespace DB | ||
{ | ||
|
||
class IExternalSchemaWriter | ||
{ | ||
public: | ||
IExternalSchemaWriter(std::string_view schema_body_, const FormatSettings & settings_) | ||
: schema_body(schema_body_) | ||
, settings(settings_) | ||
{} | ||
explicit IExternalSchemaWriter(FormatSettings settings_) | ||
: settings(std::move(settings_)) | ||
{} | ||
|
||
virtual ~IExternalSchemaWriter() = default; | ||
|
||
/// Validates the schema input. Should throw exceptions on validation failures. | ||
virtual void validate() = 0; | ||
virtual void validate(std::string_view schema_body) = 0; | ||
|
||
/// Persistents the schema. | ||
/// If the schema already exists, and replace_if_exist is false, it returns false. | ||
/// Otherwise it returns true. Throws exceptions if it fails to write. | ||
virtual bool write(bool replace_if_exist) = 0; | ||
/// Returns false if file was not written, i.e. there was an existing schema file, and it's not replaced. | ||
/// It throws exceptions if it fails to write. | ||
bool write(std::string_view schema_body, bool replace_if_exist) | ||
{ | ||
auto schema_info = getSchemaInfo(); | ||
auto already_exists = std::filesystem::exists(schema_info.absoluteSchemaPath()); | ||
if (already_exists && !replace_if_exist) | ||
return false; | ||
|
||
WriteBufferFromFile write_buffer{schema_info.absoluteSchemaPath()}; | ||
write_buffer.write(schema_body.data(), schema_body.size()); | ||
if (already_exists) | ||
onReplaced(); | ||
|
||
return true; | ||
} | ||
|
||
/// A callback will be called when a schema gets deleted. | ||
virtual void onDeleted() {} | ||
|
||
protected: | ||
std::string_view schema_body; | ||
const FormatSettings & settings; | ||
virtual String getFormatName() const = 0; | ||
|
||
/// A callback will be called when an existing schema gets replaced. | ||
virtual void onReplaced() {} | ||
|
||
FormatSchemaInfo getSchemaInfo() const | ||
{ | ||
return {settings.schema.format_schema, getFormatName(), false, settings.schema.is_server, settings.schema.format_schema_path}; | ||
} | ||
|
||
FormatSettings settings; | ||
}; | ||
|
||
} |
Oops, something went wrong.