morningman commented on a change in pull request #4438: URL: https://github.com/apache/incubator-doris/pull/4438#discussion_r492513438
########## File path: be/src/exec/odbc_scan_node.h ########## @@ -0,0 +1,96 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#ifndef DORIS_BE_SRC_QUERY_EXEC_ODBC_SCAN_NODE_H +#define DORIS_BE_SRC_QUERY_EXEC_ODBC_SCAN_NODE_H + +#include <memory> + +#include "runtime/descriptors.h" +#include "exec/scan_node.h" +#include "exec/odbc_scanner.h" + +namespace doris { + +class TextConverter; +class Tuple; +class TupleDescriptor; +class RuntimeState; +class MemPool; +class Status; + +class OdbcScanNode : public ScanNode { +public: + OdbcScanNode(ObjectPool* pool, const TPlanNode& tnode, const DescriptorTbl& descs); + ~OdbcScanNode(); + + // initialize _mysql_scanner, and create _text_converter. + virtual Status prepare(RuntimeState* state); + + // Start MySQL scan using _mysql_scanner. + virtual Status open(RuntimeState* state); + + // Fill the next row batch by calling next() on the _mysql_scanner, + // converting text data in MySQL cells to binary data. + virtual Status get_next(RuntimeState* state, RowBatch* row_batch, bool* eos); + + // Close the _mysql_scanner, and report errors. Review comment: Modify the comment ########## File path: be/src/exec/odbc_scanner.cpp ########## @@ -0,0 +1,257 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include <boost/algorithm/string.hpp> +#include <codecvt> +#include <sqlext.h> + +#include "exec/odbc_scanner.h" +#include "common/logging.h" +#include "runtime/primitive_type.h" + +#define ODBC_DISPOSE(h, ht, x, op) { auto rc = x;\ + if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) \ + { \ + return error_status(op, handle_diagnostic_record(h, ht, rc)); \ + } \ + if (rc == SQL_ERROR) \ + { \ + auto err_msg = std::string("Errro in") + std::string(op); \ + return Status::InternalError(err_msg.c_str()); \ + } \ + } \ + +static constexpr uint32_t SMALL_COLUMN_SIZE_BUFFER = 100; +// Now we only treat HLL, CHAR, VARCHAR as big column +static constexpr uint32_t BIG_COLUMN_SIZE_BUFFER = 65535; + +static std::u16string utf8_to_wstring (const std::string& str) Review comment: ```suggestion static std::u16string utf8_to_wstring(const std::string& str) ``` ########## File path: docs/zh-CN/extending-doris/odbc-of-doris.md ########## @@ -0,0 +1,217 @@ +--- +{ + "title": "ODBC of Doris", + "language": "zh-CN" +} +--- + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +# ODBC External Table Of Doris + +ODBC External Table Of Doris 提供了Doris通过数据库访问的标准接口(ODBC)来访问外部表,外部表省去了繁琐的数据导入工作,让Doris可以具有了访问各式数据库的能力,并借助Doris本身的OLAP的能力来解决外部表的数据分析问题: + + 1. 支持各种数据源接入Doris + 2. 支持Doris与各种数据源中的表联合查询,进行更加复杂的分析操作 + +本文档主要介绍该功能的实现原理、使用方式等。 + +## 名词解释 + +### Doirs相关 +* FE:Frontend,Doris 的前端节点,负责元数据管理和请求接入 +* BE:Backend,Doris 的后端节点,负责查询执行和数据存储 + +## 使用方法 + +### Doris中创建ODBC的外表 + +#### 1. 不使用Resource创建ODBC的外表 + +``` +CREATE EXTERNAL TABLE `baseall_oracle` ( + `k1` decimal(9, 3) NOT NULL COMMENT "", + `k2` char(10) NOT NULL COMMENT "", + `k3` datetime NOT NULL COMMENT "", + `k5` varchar(20) NOT NULL COMMENT "", + `k6` double NOT NULL COMMENT "" +) ENGINE=ODBC +COMMENT "ODBC" +PROPERTIES ( +"host" = "192.168.0.1", +"port" = "8086", +"user" = "test", +"password" = "test", +"database" = "test", +"table" = "baseall", +"driver" = "Oracle 19 ODBC driver", +"odbc_type" = "oracle" +); +``` + +#### 2. 通过ODBC_Resource来创建ODBC外表 (推荐使用的方式) +``` +create external resource "oracle_odbc" + properties Review comment: Indent ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org