Skip to content

Conversation

@zhangstar333
Copy link
Contributor

Proposed changes

Issue Number: close #7978

Problem Summary:

Describe the overview of changes.

Checklist(Required)

  1. Does it affect the original behavior: (Yes/No/I Don't know)
  2. Has unit tests been added: (Yes/No/No Need)
  3. Has document been added or modified: (Yes/No/No Need)
  4. Does it need to update dependencies: (Yes/No)
  5. Are there any changes that cannot be rolled back: (Yes/No)

Further comments

If this is a relatively large or complex change, kick off the discussion at dev@doris.apache.org by explaining why you chose the solution you did and what alternatives you considered, etc...

Copy link
Contributor

@HappenLee HappenLee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some problem need to change

#include "vec/sink/vtablet_sink.h"

#include "vec/sink/vmysql_table_writer.h"
namespace doris {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add space

int num_columns = _vec_output_expr_ctxs.size();

for (int i = 0; i < num_columns; ++i) {
auto column_ptr = block.get_by_position(i).column->convert_to_full_column_if_const();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do convert before call insert_row


for (int i = 0; i < num_columns; ++i) {
auto column_ptr = block.get_by_position(i).column->convert_to_full_column_if_const();
auto type_ptr = block.get_by_position(i).type;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not copy

switch (_vec_output_expr_ctxs[i]->root()->result_type()) {
case TYPE_BOOLEAN: {
auto& data = assert_cast<const vectorized::ColumnUInt8&>(*column).get_data();
fmt::format_to(_insert_stmt_buffer, "{}", std::to_string(data[row]));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not call to_string

case TYPE_VARCHAR: {
const auto& string_val =
assert_cast<const vectorized::ColumnString&>(*column).get_data_at(row);
if (string_val.data == nullptr) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DCHECK not nullptr

fmt::format_to(_insert_stmt_buffer, "{}", "NULL");
}
} else {
char* buf = new char[2 * string_val.size + 1];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unique_ptr


// Insert this to MySQL server
std::string insert_stmt = to_string(_insert_stmt_buffer);
LOG(INFO) << insert_stmt;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not log each insert query

fmt::format_to(_insert_stmt_buffer, "{}", ")");

// Insert this to MySQL server
std::string insert_stmt = to_string(_insert_stmt_buffer);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try to reduce the mem alloc

RETURN_IF_ERROR(DataSink::prepare(state));
// Prepare the exprs to run.
RETURN_IF_ERROR(VExpr::prepare(_output_expr_ctxs, state, _row_desc, _mem_tracker));
std::stringstream title;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use format to replace stringstream


#include "common/status.h"

#include <fmt/format.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to 21line up

Copy link
Contributor

@HappenLee HappenLee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@github-actions github-actions bot added the approved Indicates a PR has been approved by one committer. label Feb 14, 2022
@github-actions
Copy link
Contributor

PR approved by at least one committer and no changes requested.

@github-actions
Copy link
Contributor

PR approved by anyone and no changes requested.

@HappenLee HappenLee merged commit 25d6477 into apache:master Feb 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by one committer. reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Vectorized][Feature] Support mysql external table insert into stm

2 participants