Skip to content

Commit ca82053

Browse files
committed
Initial commit of MySQLScanner
1 parent 106664b commit ca82053

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+4058
-1
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "duckdb"]
2+
path = duckdb
3+
url = https://github.com/duckdb/duckdb

CMakeLists.txt

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
cmake_minimum_required(VERSION 3.5.0)
2+
set(TARGET_NAME mysql_scanner)
3+
project(${TARGET_NAME})
4+
5+
set(OPENSSL_USE_STATIC_LIBS TRUE)
6+
7+
find_package(OpenSSL REQUIRED)
8+
9+
link_directories(/opt/homebrew/Cellar/mysql/8.1.0/lib)
10+
#add_library()
11+
#-L -lmysqlclient -lz -lzstd -L/opt/homebrew/lib -lssl -lcrypto -lresolv
12+
include_directories(mysql/include)
13+
14+
add_subdirectory(src)
15+
16+
if(EXISTS "mysql")
17+
else()
18+
execute_process(
19+
COMMAND sh mysqlconfigure
20+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
21+
)
22+
endif()
23+
24+
set(PARAMETERS "-no-warnings")
25+
build_loadable_extension(${TARGET_NAME} ${PARAMETERS} ${ALL_OBJECT_FILES}
26+
${LIBPG_SOURCES_FULLPATH})
27+
28+
target_include_directories(
29+
${TARGET_NAME}_loadable_extension
30+
PRIVATE include mysql/include ${OPENSSL_INCLUDE_DIR})
31+
32+
if(WIN32)
33+
target_include_directories(
34+
${TARGET_NAME}_loadable_extension
35+
PRIVATE postgres/src/include/port/win32 postgres/src/port
36+
postgres/src/include/port/win32_msvc)
37+
endif()
38+
39+
target_link_libraries(${TARGET_NAME}_loadable_extension ${OPENSSL_LIBRARIES} mysqlclient z)
40+
set_property(TARGET ${TARGET_NAME}_loadable_extension PROPERTY C_STANDARD 99)
41+
42+
if(WIN32)
43+
target_link_libraries(${TARGET_NAME}_loadable_extension wsock32 ws2_32
44+
wldap32 secur32 crypt32)
45+
endif()

LICENSE-GPL

+674
Large diffs are not rendered by default.

Makefile

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
.PHONY: all clean format debug release duckdb_debug duckdb_release pull update
2+
3+
all: release
4+
5+
MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
6+
PROJ_DIR := $(dir $(MKFILE_PATH))
7+
8+
OSX_BUILD_UNIVERSAL_FLAG=
9+
ifneq (${OSX_BUILD_ARCH}, "")
10+
OSX_BUILD_UNIVERSAL_FLAG=-DOSX_BUILD_ARCH=${OSX_BUILD_ARCH}
11+
endif
12+
VCPKG_TOOLCHAIN_PATH?=
13+
ifneq ("${VCPKG_TOOLCHAIN_PATH}", "")
14+
TOOLCHAIN_FLAGS:=${TOOLCHAIN_FLAGS} -DVCPKG_MANIFEST_DIR='${PROJ_DIR}' -DVCPKG_BUILD=1 -DCMAKE_TOOLCHAIN_FILE='${VCPKG_TOOLCHAIN_PATH}'
15+
endif
16+
ifneq ("${VCPKG_TARGET_TRIPLET}", "")
17+
TOOLCHAIN_FLAGS:=${TOOLCHAIN_FLAGS} -DVCPKG_TARGET_TRIPLET='${VCPKG_TARGET_TRIPLET}'
18+
endif
19+
20+
ifeq ($(GEN),ninja)
21+
GENERATOR=-G "Ninja"
22+
FORCE_COLOR=-DFORCE_COLORED_OUTPUT=1
23+
endif
24+
25+
BUILD_FLAGS=-DEXTENSION_STATIC_BUILD=1 -DBUILD_EXTENSIONS="tpch;tpcds" ${OSX_BUILD_UNIVERSAL_FLAG} ${STATIC_LIBCPP} ${TOOLCHAIN_FLAGS}
26+
27+
CLIENT_FLAGS :=
28+
29+
# These flags will make DuckDB build the extension
30+
EXTENSION_FLAGS=\
31+
-DDUCKDB_EXTENSION_NAMES="mysql_scanner" \
32+
-DDUCKDB_EXTENSION_MYSQL_SCANNER_PATH="$(PROJ_DIR)" \
33+
-DDUCKDB_EXTENSION_MYSQL_SCANNER_SHOULD_LINK=0 \
34+
-DDUCKDB_EXTENSION_MYSQL_SCANNER_LOAD_TESTS=1 \
35+
-DDUCKDB_EXTENSION_MYSQL_SCANNER_TEST_PATH="$(PROJ_DIR)test"
36+
37+
pull:
38+
git submodule init
39+
git submodule update --recursive --remote
40+
41+
clean:
42+
rm -rf build
43+
rm -rf testext
44+
cd duckdb && make clean
45+
46+
# Main build
47+
debug:
48+
mkdir -p build/debug && \
49+
cmake $(GENERATOR) $(FORCE_COLOR) $(EXTENSION_FLAGS) ${BUILD_FLAGS} ${CLIENT_FLAGS} -DCMAKE_BUILD_TYPE=Debug -S ./duckdb/ -B build/debug && \
50+
cmake --build build/debug --config Debug
51+
52+
reldebug:
53+
mkdir -p build/reldebug && \
54+
cmake $(GENERATOR) $(FORCE_COLOR) $(EXTENSION_FLAGS) ${BUILD_FLAGS} ${CLIENT_FLAGS} -DCMAKE_BUILD_TYPE=RelWithDebInfo -S ./duckdb/ -B build/reldebug && \
55+
cmake --build build/reldebug --config RelWithDebInfo
56+
57+
release:
58+
mkdir -p build/release && \
59+
cmake $(GENERATOR) $(FORCE_COLOR) $(EXTENSION_FLAGS) ${BUILD_FLAGS} ${CLIENT_FLAGS} -DCMAKE_BUILD_TYPE=Release -S ./duckdb/ -B build/release && \
60+
cmake --build build/release --config Release
61+
62+
# Main tests
63+
test: test_release
64+
65+
test_release: release
66+
./build/release/test/unittest "$(PROJ_DIR)test/*"
67+
68+
test_debug: debug
69+
./build/debug/test/unittest "$(PROJ_DIR)test/*"
70+
71+
format:
72+
cp duckdb/.clang-format .
73+
find src/ -iname *.hpp -o -iname *.cpp | xargs clang-format --sort-includes=0 -style=file -i
74+
cmake-format -i CMakeLists.txt
75+
rm .clang-format
76+
77+
update:
78+
git submodule update --remote --merge

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# mysql_scanner
1+
# DuckDB MySQL extension

duckdb

Submodule duckdb added at 401c806

mysqlconfigure

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
rm -rf mysql
2+
mkdir mysql
3+
curl -s -L https://github.com/mysql/mysql-server/archive/refs/tags/mysql-8.1.0.tar.gz | tar xz --strip-components 1 -C mysql

src/CMakeLists.txt

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
include_directories(include)
2+
3+
add_subdirectory(storage)
4+
5+
add_library(
6+
mysql_ext_library OBJECT
7+
mysql_connection.cpp
8+
mysql_extension.cpp
9+
mysql_filter_pushdown.cpp
10+
mysql_scanner.cpp
11+
mysql_storage.cpp
12+
mysql_utils.cpp)
13+
set(ALL_OBJECT_FILES
14+
${ALL_OBJECT_FILES} $<TARGET_OBJECTS:mysql_ext_library>
15+
PARENT_SCOPE)

src/include/mysql_connection.hpp

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
//===----------------------------------------------------------------------===//
2+
// DuckDB
3+
//
4+
// mysql_connection.hpp
5+
//
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#pragma once
10+
11+
#include "mysql_utils.hpp"
12+
#include "mysql_result.hpp"
13+
14+
namespace duckdb {
15+
class MySQLBinaryWriter;
16+
class MySQLTextWriter;
17+
struct MySQLBinaryReader;
18+
class MySQLSchemaEntry;
19+
class MySQLTableEntry;
20+
class MySQLStatement;
21+
class MySQLResult;
22+
struct IndexInfo;
23+
24+
struct OwnedMySQLConnection {
25+
explicit OwnedMySQLConnection(MYSQL *conn = nullptr) : connection(conn) {
26+
}
27+
~OwnedMySQLConnection() {
28+
if (!connection) {
29+
return;
30+
}
31+
mysql_close(connection);
32+
connection = nullptr;
33+
}
34+
35+
MYSQL *connection;
36+
};
37+
38+
class MySQLConnection {
39+
public:
40+
explicit MySQLConnection(shared_ptr<OwnedMySQLConnection> connection = nullptr);
41+
~MySQLConnection();
42+
// disable copy constructors
43+
MySQLConnection(const MySQLConnection &other) = delete;
44+
MySQLConnection &operator=(const MySQLConnection &) = delete;
45+
//! enable move constructors
46+
MySQLConnection(MySQLConnection &&other) noexcept;
47+
MySQLConnection &operator=(MySQLConnection &&) noexcept;
48+
49+
public:
50+
static MySQLConnection Open(const string &connection_string);
51+
void Execute(const string &query);
52+
unique_ptr<MySQLResult> Query(const string &query);
53+
54+
vector<IndexInfo> GetIndexInfo(const string &table_name);
55+
56+
bool IsOpen();
57+
void Close();
58+
59+
shared_ptr<OwnedMySQLConnection> GetConnection() {
60+
return connection;
61+
}
62+
string GetDSN() {
63+
return dsn;
64+
}
65+
66+
MYSQL *GetConn() {
67+
if (!connection || !connection->connection) {
68+
throw InternalException("MySQLConnection::GetConn - no connection available");
69+
}
70+
return connection->connection;
71+
}
72+
73+
static void DebugSetPrintQueries(bool print);
74+
static bool DebugPrintQueries();
75+
76+
private:
77+
MYSQL_RES *MySQLExecute(const string &query);
78+
79+
shared_ptr<OwnedMySQLConnection> connection;
80+
string dsn;
81+
};
82+
83+
} // namespace duckdb

0 commit comments

Comments
 (0)