be/src/exec/sink/writer/vjdbc_table_writer.cpp
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #include "exec/sink/writer/vjdbc_table_writer.h" |
19 | | |
20 | | #include <gen_cpp/DataSinks_types.h> |
21 | | #include <stdint.h> |
22 | | |
23 | | #include <sstream> |
24 | | |
25 | | #include "core/binary_cast.hpp" |
26 | | #include "core/block/block.h" |
27 | | #include "exprs/vexpr.h" |
28 | | #include "exprs/vexpr_context.h" |
29 | | |
30 | | namespace doris { |
31 | | |
32 | 0 | JdbcConnectorParam VJdbcTableWriter::create_connect_param(const doris::TDataSink& t_sink) { |
33 | 0 | const TJdbcTableSink& t_jdbc_sink = t_sink.jdbc_table_sink; |
34 | |
|
35 | 0 | JdbcConnectorParam jdbc_param; |
36 | |
|
37 | 0 | jdbc_param.catalog_id = t_jdbc_sink.jdbc_table.catalog_id; |
38 | 0 | jdbc_param.jdbc_url = t_jdbc_sink.jdbc_table.jdbc_url; |
39 | 0 | jdbc_param.user = t_jdbc_sink.jdbc_table.jdbc_user; |
40 | 0 | jdbc_param.passwd = t_jdbc_sink.jdbc_table.jdbc_password; |
41 | 0 | jdbc_param.driver_class = t_jdbc_sink.jdbc_table.jdbc_driver_class; |
42 | 0 | jdbc_param.driver_path = t_jdbc_sink.jdbc_table.jdbc_driver_url; |
43 | 0 | jdbc_param.driver_checksum = t_jdbc_sink.jdbc_table.jdbc_driver_checksum; |
44 | 0 | jdbc_param.resource_name = t_jdbc_sink.jdbc_table.jdbc_resource_name; |
45 | 0 | jdbc_param.table_type = t_jdbc_sink.table_type; |
46 | 0 | jdbc_param.query_string = t_jdbc_sink.insert_sql; |
47 | 0 | jdbc_param.table_name = t_jdbc_sink.jdbc_table.jdbc_table_name; |
48 | 0 | jdbc_param.use_transaction = t_jdbc_sink.use_transaction; |
49 | 0 | jdbc_param.connection_pool_min_size = t_jdbc_sink.jdbc_table.connection_pool_min_size; |
50 | 0 | jdbc_param.connection_pool_max_size = t_jdbc_sink.jdbc_table.connection_pool_max_size; |
51 | 0 | jdbc_param.connection_pool_max_wait_time = t_jdbc_sink.jdbc_table.connection_pool_max_wait_time; |
52 | 0 | jdbc_param.connection_pool_max_life_time = t_jdbc_sink.jdbc_table.connection_pool_max_life_time; |
53 | 0 | jdbc_param.connection_pool_keep_alive = t_jdbc_sink.jdbc_table.connection_pool_keep_alive; |
54 | |
|
55 | 0 | return jdbc_param; |
56 | 0 | } |
57 | | |
58 | | VJdbcTableWriter::VJdbcTableWriter(const TDataSink& t_sink, |
59 | | const VExprContextSPtrs& output_expr_ctxs, |
60 | | std::shared_ptr<Dependency> dep, |
61 | | std::shared_ptr<Dependency> fin_dep) |
62 | 0 | : AsyncResultWriter(output_expr_ctxs, dep, fin_dep), |
63 | 0 | JdbcConnector(create_connect_param(t_sink)) {} |
64 | | |
65 | 0 | Status VJdbcTableWriter::write(RuntimeState* state, Block& block) { |
66 | 0 | Block output_block; |
67 | 0 | RETURN_IF_ERROR(_projection_block(block, &output_block)); |
68 | 0 | auto num_rows = output_block.rows(); |
69 | |
|
70 | 0 | uint32_t start_send_row = 0; |
71 | 0 | uint32_t num_row_sent = 0; |
72 | 0 | while (start_send_row < num_rows) { |
73 | 0 | RETURN_IF_ERROR(append(&output_block, _vec_output_expr_ctxs, start_send_row, &num_row_sent, |
74 | 0 | _conn_param.table_type)); |
75 | 0 | start_send_row += num_row_sent; |
76 | 0 | num_row_sent = 0; |
77 | 0 | } |
78 | | |
79 | 0 | return Status::OK(); |
80 | 0 | } |
81 | | |
82 | | } // namespace doris |