Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape table names in delete and update #58

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/motherduck_destination_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,16 @@ void process_file(
"Could not convert Arrow batch reader to an array stream for file <" +
props.filename + ">: " + status.message());
}
mdlog::info("ArrowArrayStream created for file " + props.filename);

duckdb_connection c_con = reinterpret_cast<duckdb_connection>(&con);
duckdb_arrow_stream c_arrow_stream = (duckdb_arrow_stream)&arrow_array_stream;
mdlog::info("duckdb_arrow_stream created for file " + props.filename);
duckdb_arrow_scan(c_con, "arrow_view", c_arrow_stream);
mdlog::info("duckdb_arrow_scan completed for file " + props.filename);

process_view("localmem.arrow_view");
process_view("\"localmem\".\"arrow_view\"");
mdlog::info("view processed for file " + props.filename);

arrow_array_stream.release(&arrow_array_stream);
}
Expand Down Expand Up @@ -386,6 +390,7 @@ DestinationSdkImpl::WriteBatch(::grpc::ServerContext *context,
[](const column_def &col) { return col.name; });

for (auto &filename : request->replace_files()) {
mdlog::info("Processing replace file " + filename);
const auto decryption_key = get_encryption_key(
filename, request->keys(), request->csv().encryption());

Expand All @@ -397,7 +402,7 @@ DestinationSdkImpl::WriteBatch(::grpc::ServerContext *context,
});
}
for (auto &filename : request->update_files()) {

mdlog::info("Processing update file " + filename);
auto decryption_key = get_encryption_key(filename, request->keys(),
request->csv().encryption());
IngestProperties props(filename, decryption_key, column_names,
Expand All @@ -409,6 +414,7 @@ DestinationSdkImpl::WriteBatch(::grpc::ServerContext *context,
});
}
for (auto &filename : request->delete_files()) {
mdlog::info("Processing delete file " + filename);
auto decryption_key = get_encryption_key(filename, request->keys(),
request->csv().encryption());
std::vector<std::string> empty;
Expand Down
8 changes: 4 additions & 4 deletions src/sql_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,8 @@ void update_values(duckdb::Connection &con, const table_def &table,
write_joined(
sql, columns_pk,
[&](const std::string &quoted_col, std::ostringstream &out) {
out << table.table_name << "." << quoted_col << " = "
<< staging_table_name << "." << quoted_col;
out << KeywordHelper::WriteQuoted(table.table_name, '"') << "."
<< quoted_col << " = " << staging_table_name << "." << quoted_col;
},
" AND ");

Expand All @@ -474,8 +474,8 @@ void delete_rows(duckdb::Connection &con, const table_def &table,
write_joined(
sql, columns_pk,
[&](const std::string &quoted_col, std::ostringstream &out) {
out << table.table_name << "." << quoted_col << " = "
<< staging_table_name << "." << quoted_col;
out << KeywordHelper::WriteQuoted(table.table_name, '"') << "."
<< quoted_col << " = " << staging_table_name << "." << quoted_col;
},
" AND ");

Expand Down
Loading