HappenLee commented on a change in pull request #4438:
URL: https://github.com/apache/incubator-doris/pull/4438#discussion_r477156203



##########
File path: be/src/exec/odbc_scanner.cpp
##########
@@ -0,0 +1,248 @@
+// 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;
+
+namespace doris {
+
+ODBCScanner::ODBCScanner(const ODBCScannerParam& param)
+        : _connect_string(build_connect_string(param)),
+          _type(param.type),
+          _tuple_desc(param.tuple_desc),
+          _is_open(false),
+          _field_num(0),
+          _row_count(0),
+          _env(nullptr),
+          _dbc(nullptr),
+          _stmt(nullptr) {
+}
+
+ODBCScanner::~ODBCScanner() {
+    if (_stmt != nullptr) {
+        SQLFreeHandle(SQL_HANDLE_STMT, _stmt);
+    }
+
+    if (_dbc != nullptr) {
+        SQLDisconnect(_dbc);
+        SQLFreeHandle(SQL_HANDLE_DBC, _dbc);
+    }
+
+    if (_env != nullptr) {
+        SQLFreeHandle(SQL_HANDLE_ENV, _env);
+    }
+}
+
+Status ODBCScanner::open() {
+    if (_is_open) {
+        LOG(INFO) << "this scanner already opened";
+        return Status::OK();
+    }
+
+    // Allocate an environment
+    if (SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &_env) != SQL_SUCCESS) 
{
+        return Status::InternalError("alloc env failed");
+    }
+    // We want ODBC 3 support
+    ODBC_DISPOSE(_env, SQL_HANDLE_ENV, SQLSetEnvAttr(_env, 
SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0), "set env attr");
+    // Allocate a connection handle
+    ODBC_DISPOSE(_env, SQL_HANDLE_ENV, SQLAllocHandle(SQL_HANDLE_DBC, _env, 
&_dbc), "alloc dbc");
+    // Connect to the Database
+    ODBC_DISPOSE(_dbc, SQL_HANDLE_DBC, SQLDriverConnect(_dbc, NULL, 
(SQLCHAR*)_connect_string.c_str(), SQL_NTS,
+                           NULL, 0, NULL, SQL_DRIVER_COMPLETE_REQUIRED), 
"driver connect");
+
+    LOG(INFO) << "connect success:";

Review comment:
       ok




----------------------------------------------------------------
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

Reply via email to