clickhouse-native 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/ext/clickhouse_native/client.cpp +847 -0
- data/ext/clickhouse_native/extconf.rb +101 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/.clang-format +11 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/.git +1 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/.gitattributes +63 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/.github/CODEOWNERS +1 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/.github/workflows/linux.yml +139 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/.github/workflows/macos.yml +87 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/.github/workflows/windows_mingw.yml +102 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/.github/workflows/windows_msvc.yml +74 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/.gitignore +280 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/.travis.yml +62 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/CMakeLists.txt +157 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/LICENSE +206 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/README.md +260 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/CMakeLists.txt +246 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/buffer.h +10 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/compressed.cpp +258 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/compressed.h +48 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/endpoints_iterator.cpp +20 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/endpoints_iterator.h +34 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/input.cpp +96 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/input.h +103 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/open_telemetry.h +23 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/output.cpp +119 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/output.h +142 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/platform.cpp +1 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/platform.h +33 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/projected_iterator.h +55 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/singleton.h +11 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/socket.cpp +489 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/socket.h +177 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/sslsocket.cpp +307 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/sslsocket.h +111 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/string_utils.h +28 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/string_view.h +142 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/uuid.h +10 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/wire_format.cpp +177 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/base/wire_format.h +79 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/block.cpp +134 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/block.h +114 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/client.cpp +1269 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/client.h +320 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/array.cpp +175 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/array.h +321 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/column.cpp +24 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/column.h +107 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/date.cpp +365 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/date.h +245 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/decimal.cpp +255 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/decimal.h +50 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/enum.cpp +123 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/enum.h +65 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/factory.cpp +285 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/factory.h +14 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/geo.cpp +108 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/geo.h +79 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/ip4.cpp +117 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/ip4.h +71 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/ip6.cpp +108 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/ip6.h +66 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/itemview.cpp +101 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/itemview.h +86 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/lowcardinality.cpp +527 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/lowcardinality.h +221 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/lowcardinalityadaptor.h +63 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/map.cpp +87 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/map.h +257 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/nothing.h +87 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/nullable.cpp +109 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/nullable.h +153 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/numeric.cpp +126 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/numeric.h +88 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/string.cpp +333 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/string.h +145 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/time.cpp +155 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/time.h +118 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/tuple.cpp +106 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/tuple.h +178 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/utils.h +41 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/uuid.cpp +80 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/columns/uuid.h +58 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/error_codes.h +595 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/exceptions.h +66 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/protocol.h +54 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/query.cpp +25 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/query.h +246 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/server_exception.h +16 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/types/type_parser.cpp +314 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/types/type_parser.h +89 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/types/types.cpp +484 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/types/types.h +397 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/clickhouse/version.h +14 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/cmake/Findcityhash.cmake +26 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/cmake/Findlz4.cmake +39 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/cmake/Findzstd.cmake +39 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/cmake/cpp17.cmake +8 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/cmake/openssl.cmake +8 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/cmake/subdirs.cmake +5 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/cmake/version.cmake +87 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/absl/absl/CMakeLists.txt +9 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/absl/absl/base/attributes.h +682 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/absl/absl/base/config.h +714 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/absl/absl/base/internal/bits.h +219 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/absl/absl/base/macros.h +147 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/absl/absl/base/optimization.h +241 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/absl/absl/base/options.h +238 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/absl/absl/base/policy_checks.h +111 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/absl/absl/base/port.h +26 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/absl/absl/numeric/int128.cc +390 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/absl/absl/numeric/int128.h +1092 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/absl/absl/numeric/int128_have_intrinsic.inc +302 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/absl/absl/numeric/int128_no_intrinsic.inc +308 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/cityhash/cityhash/BUCK +13 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/cityhash/cityhash/CMakeLists.txt +7 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/cityhash/cityhash/COPYING +19 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/cityhash/cityhash/city.cc +469 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/cityhash/cityhash/city.h +90 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/cityhash/cityhash/citycrc.h +43 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/cityhash/cityhash/config.h +118 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/BUCK +14 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/CMakeLists.txt +4 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/LICENSE +28 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/README.md +1 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/gtest-death-test.h +346 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/gtest-matchers.h +930 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/gtest-message.h +219 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/gtest-param-test.h +507 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/gtest-printers.h +1029 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/gtest-spi.h +238 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/gtest-test-part.h +184 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/gtest-typed-test.h +329 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/gtest.h +2495 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/gtest_pred_impl.h +359 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/gtest_prod.h +61 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/internal/custom/README.md +56 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/internal/custom/gtest-port.h +37 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/internal/custom/gtest-printers.h +42 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/internal/custom/gtest.h +37 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/internal/gtest-death-test-internal.h +304 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/internal/gtest-filepath.h +211 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/internal/gtest-internal.h +1560 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/internal/gtest-param-util.h +947 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/internal/gtest-port-arch.h +114 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/internal/gtest-port.h +2389 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/internal/gtest-string.h +175 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/include/gtest/internal/gtest-type-util.h +183 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/src/gtest-all.cc +48 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/src/gtest-death-test.cc +1644 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/src/gtest-filepath.cc +369 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/src/gtest-internal-inl.h +1221 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/src/gtest-matchers.cc +97 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/src/gtest-port.cc +1433 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/src/gtest-printers.cc +533 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/src/gtest-test-part.cc +108 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/src/gtest-typed-test.cc +107 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/src/gtest.cc +6746 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/gtest/src/gtest_main.cc +54 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/lz4/lz4/BUCK +13 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/lz4/lz4/CMakeLists.txt +8 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/lz4/lz4/LICENSE +24 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/lz4/lz4/lz4.c +2402 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/lz4/lz4/lz4.h +764 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/lz4/lz4/lz4hc.c +1554 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/lz4/lz4/lz4hc.h +438 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/BUCK +232 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/CMakeLists.txt +115 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/LICENSE +30 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/allocations.h +55 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/bits.h +200 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/bitstream.h +437 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/compiler.h +358 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/cpu.h +213 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/debug.c +24 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/debug.h +107 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/entropy_common.c +340 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/error_private.c +63 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/error_private.h +159 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/fse.h +639 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/fse_decompress.c +311 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/huf.h +273 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/mem.h +435 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/pool.c +371 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/pool.h +90 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/portability_macros.h +156 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/threading.c +176 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/threading.h +150 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/xxhash.c +24 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/xxhash.h +5686 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/zstd_common.c +48 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/zstd_deps.h +111 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/zstd_internal.h +392 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/common/zstd_trace.h +163 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/clevels.h +134 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/fse_compress.c +624 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/hist.c +181 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/hist.h +75 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/huf_compress.c +1435 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_compress.c +7032 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_compress_internal.h +1532 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_compress_literals.c +235 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_compress_literals.h +39 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_compress_sequences.c +442 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_compress_sequences.h +54 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_compress_superblock.c +577 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_compress_superblock.h +32 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_cwksp.h +742 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_double_fast.c +758 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_double_fast.h +39 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_fast.c +960 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_fast.h +38 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_lazy.c +2157 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_lazy.h +127 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_ldm.c +724 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_ldm.h +117 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_ldm_geartab.h +106 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_opt.c +1472 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstd_opt.h +56 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstdmt_compress.c +1867 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/compress/zstdmt_compress.h +113 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/decompress/huf_decompress.c +1882 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/decompress/huf_decompress_amd64.S +576 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/decompress/zstd_ddict.c +244 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/decompress/zstd_ddict.h +44 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/decompress/zstd_decompress.c +2355 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/decompress/zstd_decompress_block.c +2192 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/decompress/zstd_decompress_block.h +73 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/decompress/zstd_decompress_internal.h +238 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/dictBuilder/cover.c +1257 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/dictBuilder/cover.h +158 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/dictBuilder/divsufsort.c +1913 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/dictBuilder/divsufsort.h +67 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/dictBuilder/fastcover.c +766 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/dictBuilder/zdict.c +1127 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/legacy/zstd_legacy.h +422 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/legacy/zstd_v01.c +2125 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/legacy/zstd_v01.h +94 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/legacy/zstd_v02.c +3477 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/legacy/zstd_v02.h +93 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/legacy/zstd_v03.c +3117 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/legacy/zstd_v03.h +93 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/legacy/zstd_v04.c +3605 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/legacy/zstd_v04.h +142 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/legacy/zstd_v05.c +4004 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/legacy/zstd_v05.h +162 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/legacy/zstd_v06.c +4113 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/legacy/zstd_v06.h +172 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/legacy/zstd_v07.c +4498 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/legacy/zstd_v07.h +187 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/zdict.h +474 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/zstd.h +3020 -0
- data/ext/clickhouse_native/vendor/clickhouse-cpp/contrib/zstd/zstd/zstd_errors.h +114 -0
- data/lib/clickhouse_native/clickhouse_native.bundle +0 -0
- data/lib/clickhouse_native/client.rb +50 -0
- data/lib/clickhouse_native/errors.rb +23 -0
- data/lib/clickhouse_native/pool.rb +49 -0
- data/lib/clickhouse_native/version.rb +3 -0
- data/lib/clickhouse_native.rb +8 -0
- metadata +369 -0
|
@@ -0,0 +1,847 @@
|
|
|
1
|
+
#include <ruby.h>
|
|
2
|
+
#include <ruby/thread.h>
|
|
3
|
+
|
|
4
|
+
#include <clickhouse/client.h>
|
|
5
|
+
#include <clickhouse/columns/array.h>
|
|
6
|
+
#include <clickhouse/columns/date.h>
|
|
7
|
+
#include <clickhouse/columns/enum.h>
|
|
8
|
+
#include <clickhouse/columns/factory.h>
|
|
9
|
+
#include <clickhouse/columns/lowcardinality.h>
|
|
10
|
+
#include <clickhouse/columns/map.h>
|
|
11
|
+
#include <clickhouse/columns/numeric.h>
|
|
12
|
+
#include <clickhouse/columns/nullable.h>
|
|
13
|
+
#include <clickhouse/columns/string.h>
|
|
14
|
+
#include <clickhouse/columns/tuple.h>
|
|
15
|
+
#include <clickhouse/exceptions.h>
|
|
16
|
+
#include <clickhouse/types/types.h>
|
|
17
|
+
|
|
18
|
+
#include <cstdint>
|
|
19
|
+
#include <exception>
|
|
20
|
+
#include <memory>
|
|
21
|
+
#include <string>
|
|
22
|
+
#include <system_error>
|
|
23
|
+
#include <vector>
|
|
24
|
+
|
|
25
|
+
using namespace clickhouse;
|
|
26
|
+
|
|
27
|
+
static VALUE rb_mClickhouseNative;
|
|
28
|
+
static VALUE rb_cClient;
|
|
29
|
+
|
|
30
|
+
static VALUE err_base, err_connection, err_timeout, err_protocol,
|
|
31
|
+
err_server, err_encoder, err_decoder, err_unsupported;
|
|
32
|
+
|
|
33
|
+
// Internal exception used to tag encoder failures and drive them through
|
|
34
|
+
// raise_mapped_ex -> err_encoder without rb_raising from inside a try block.
|
|
35
|
+
namespace chn {
|
|
36
|
+
class EncoderFailure : public clickhouse::Error {
|
|
37
|
+
using clickhouse::Error::Error;
|
|
38
|
+
};
|
|
39
|
+
} // namespace chn
|
|
40
|
+
|
|
41
|
+
// ------------------------------------------------------------------
|
|
42
|
+
// Error mapping
|
|
43
|
+
// ------------------------------------------------------------------
|
|
44
|
+
|
|
45
|
+
static void raise_mapped_ex(const std::exception& e) {
|
|
46
|
+
if (auto* se = dynamic_cast<const ServerException*>(&e)) {
|
|
47
|
+
const auto& exc = se->GetException();
|
|
48
|
+
VALUE err = rb_exc_new_cstr(err_server, exc.display_text.c_str());
|
|
49
|
+
rb_ivar_set(err, rb_intern("@server_code"), INT2NUM(exc.code));
|
|
50
|
+
rb_ivar_set(err, rb_intern("@server_name"),
|
|
51
|
+
rb_utf8_str_new(exc.name.data(), exc.name.size()));
|
|
52
|
+
rb_ivar_set(err, rb_intern("@server_stacktrace"),
|
|
53
|
+
rb_utf8_str_new(exc.stack_trace.data(), exc.stack_trace.size()));
|
|
54
|
+
rb_exc_raise(err);
|
|
55
|
+
}
|
|
56
|
+
if (dynamic_cast<const chn::EncoderFailure*>(&e)) {
|
|
57
|
+
rb_raise(err_encoder, "%s", e.what());
|
|
58
|
+
}
|
|
59
|
+
if (dynamic_cast<const ProtocolError*>(&e)) {
|
|
60
|
+
rb_raise(err_protocol, "%s", e.what());
|
|
61
|
+
}
|
|
62
|
+
if (dynamic_cast<const UnimplementedError*>(&e)) {
|
|
63
|
+
rb_raise(err_unsupported, "%s", e.what());
|
|
64
|
+
}
|
|
65
|
+
if (dynamic_cast<const ValidationError*>(&e)) {
|
|
66
|
+
rb_raise(err_decoder, "%s", e.what());
|
|
67
|
+
}
|
|
68
|
+
if (auto* se = dynamic_cast<const std::system_error*>(&e)) {
|
|
69
|
+
auto code = se->code();
|
|
70
|
+
if (code == std::errc::timed_out || code == std::errc::connection_aborted) {
|
|
71
|
+
rb_raise(err_timeout, "%s", e.what());
|
|
72
|
+
}
|
|
73
|
+
rb_raise(err_connection, "%s", e.what());
|
|
74
|
+
}
|
|
75
|
+
rb_raise(err_base, "%s", e.what());
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// ------------------------------------------------------------------
|
|
79
|
+
// Type codec (value decoder)
|
|
80
|
+
// ------------------------------------------------------------------
|
|
81
|
+
|
|
82
|
+
static int64_t pow10_i64(size_t n) {
|
|
83
|
+
int64_t r = 1;
|
|
84
|
+
for (size_t i = 0; i < n; i++) r *= 10;
|
|
85
|
+
return r;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
static VALUE value_at(const ColumnRef& col, size_t idx) {
|
|
89
|
+
auto type = col->Type();
|
|
90
|
+
switch (type->GetCode()) {
|
|
91
|
+
case Type::Int8: return INT2NUM(col->As<ColumnInt8>()->At(idx));
|
|
92
|
+
case Type::Int16: return INT2NUM(col->As<ColumnInt16>()->At(idx));
|
|
93
|
+
case Type::Int32: return INT2NUM(col->As<ColumnInt32>()->At(idx));
|
|
94
|
+
case Type::Int64: return LL2NUM(col->As<ColumnInt64>()->At(idx));
|
|
95
|
+
case Type::UInt8: return UINT2NUM(col->As<ColumnUInt8>()->At(idx));
|
|
96
|
+
case Type::UInt16: return UINT2NUM(col->As<ColumnUInt16>()->At(idx));
|
|
97
|
+
case Type::UInt32: return UINT2NUM(col->As<ColumnUInt32>()->At(idx));
|
|
98
|
+
case Type::UInt64: return ULL2NUM(col->As<ColumnUInt64>()->At(idx));
|
|
99
|
+
case Type::Float32: return DBL2NUM(col->As<ColumnFloat32>()->At(idx));
|
|
100
|
+
case Type::Float64: return DBL2NUM(col->As<ColumnFloat64>()->At(idx));
|
|
101
|
+
|
|
102
|
+
case Type::String: {
|
|
103
|
+
auto sv = col->As<ColumnString>()->At(idx);
|
|
104
|
+
return rb_utf8_str_new(sv.data(), sv.size());
|
|
105
|
+
}
|
|
106
|
+
case Type::FixedString: {
|
|
107
|
+
auto sv = col->As<ColumnFixedString>()->At(idx);
|
|
108
|
+
return rb_utf8_str_new(sv.data(), sv.size());
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
case Type::Date: {
|
|
112
|
+
auto t = col->As<ColumnDate>()->At(idx);
|
|
113
|
+
return rb_time_new(t, 0);
|
|
114
|
+
}
|
|
115
|
+
case Type::Date32: {
|
|
116
|
+
auto t = col->As<ColumnDate32>()->At(idx);
|
|
117
|
+
return rb_time_new(t, 0);
|
|
118
|
+
}
|
|
119
|
+
case Type::DateTime: {
|
|
120
|
+
auto t = col->As<ColumnDateTime>()->At(idx);
|
|
121
|
+
return rb_time_new(t, 0);
|
|
122
|
+
}
|
|
123
|
+
case Type::DateTime64: {
|
|
124
|
+
auto ct = col->As<ColumnDateTime64>();
|
|
125
|
+
int64_t ticks = ct->At(idx);
|
|
126
|
+
size_t prec = type->As<DateTime64Type>()->GetPrecision();
|
|
127
|
+
int64_t denom = pow10_i64(prec);
|
|
128
|
+
int64_t secs = ticks / denom;
|
|
129
|
+
int64_t frac = ticks % denom;
|
|
130
|
+
int64_t usec = (prec <= 6) ? frac * pow10_i64(6 - prec)
|
|
131
|
+
: frac / pow10_i64(prec - 6);
|
|
132
|
+
return rb_time_new(secs, usec);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
case Type::Array: {
|
|
136
|
+
auto arr = col->As<ColumnArray>();
|
|
137
|
+
auto inner = arr->GetAsColumn(idx);
|
|
138
|
+
size_t sz = inner->Size();
|
|
139
|
+
VALUE ary = rb_ary_new_capa(sz);
|
|
140
|
+
for (size_t i = 0; i < sz; i++) rb_ary_push(ary, value_at(inner, i));
|
|
141
|
+
return ary;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
case Type::Nullable: {
|
|
145
|
+
auto n = col->As<ColumnNullable>();
|
|
146
|
+
if (n->IsNull(idx)) return Qnil;
|
|
147
|
+
return value_at(n->Nested(), idx);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
case Type::LowCardinality: {
|
|
151
|
+
auto lc = col->As<ColumnLowCardinality>();
|
|
152
|
+
auto sv = lc->GetItem(idx).AsBinaryData();
|
|
153
|
+
return rb_utf8_str_new(sv.data(), sv.size());
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
case Type::Map: {
|
|
157
|
+
auto map_col = col->As<ColumnMap>();
|
|
158
|
+
auto tuples = map_col->GetAsColumn(idx);
|
|
159
|
+
auto tuple = tuples->As<ColumnTuple>();
|
|
160
|
+
if (!tuple || tuple->TupleSize() != 2) {
|
|
161
|
+
rb_raise(err_decoder, "clickhouse-native: malformed Map column");
|
|
162
|
+
}
|
|
163
|
+
auto keys = (*tuple)[0];
|
|
164
|
+
auto vals = (*tuple)[1];
|
|
165
|
+
size_t n = keys->Size();
|
|
166
|
+
VALUE h = rb_hash_new();
|
|
167
|
+
for (size_t i = 0; i < n; i++) {
|
|
168
|
+
rb_hash_aset(h, value_at(keys, i), value_at(vals, i));
|
|
169
|
+
}
|
|
170
|
+
return h;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
case Type::Tuple: {
|
|
174
|
+
auto t = col->As<ColumnTuple>();
|
|
175
|
+
size_t sz = t->TupleSize();
|
|
176
|
+
VALUE ary = rb_ary_new_capa(sz);
|
|
177
|
+
for (size_t i = 0; i < sz; i++) rb_ary_push(ary, value_at((*t)[i], idx));
|
|
178
|
+
return ary;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
case Type::Enum8: {
|
|
182
|
+
auto sv = col->As<ColumnEnum8>()->NameAt(idx);
|
|
183
|
+
return ID2SYM(rb_intern2(sv.data(), sv.size()));
|
|
184
|
+
}
|
|
185
|
+
case Type::Enum16: {
|
|
186
|
+
auto sv = col->As<ColumnEnum16>()->NameAt(idx);
|
|
187
|
+
return ID2SYM(rb_intern2(sv.data(), sv.size()));
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
default:
|
|
191
|
+
rb_raise(err_unsupported,
|
|
192
|
+
"clickhouse-native: unsupported column type %s (code=%d)",
|
|
193
|
+
type->GetName().c_str(), static_cast<int>(type->GetCode()));
|
|
194
|
+
}
|
|
195
|
+
return Qnil;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// ------------------------------------------------------------------
|
|
199
|
+
// Write codec (value encoder for inserts)
|
|
200
|
+
// ------------------------------------------------------------------
|
|
201
|
+
|
|
202
|
+
static void append_value(const ColumnRef& col, VALUE value);
|
|
203
|
+
|
|
204
|
+
// Append a zero/default value; used for the nested column of Nullable when
|
|
205
|
+
// the flag is set to null. We never expose these bytes to the caller.
|
|
206
|
+
static void append_default(const ColumnRef& col) {
|
|
207
|
+
auto type = col->Type();
|
|
208
|
+
switch (type->GetCode()) {
|
|
209
|
+
case Type::Int8: col->As<ColumnInt8>()->Append(0); return;
|
|
210
|
+
case Type::Int16: col->As<ColumnInt16>()->Append(0); return;
|
|
211
|
+
case Type::Int32: col->As<ColumnInt32>()->Append(0); return;
|
|
212
|
+
case Type::Int64: col->As<ColumnInt64>()->Append(0); return;
|
|
213
|
+
case Type::UInt8: col->As<ColumnUInt8>()->Append(0); return;
|
|
214
|
+
case Type::UInt16: col->As<ColumnUInt16>()->Append(0); return;
|
|
215
|
+
case Type::UInt32: col->As<ColumnUInt32>()->Append(0); return;
|
|
216
|
+
case Type::UInt64: col->As<ColumnUInt64>()->Append(0); return;
|
|
217
|
+
case Type::Float32: col->As<ColumnFloat32>()->Append(0); return;
|
|
218
|
+
case Type::Float64: col->As<ColumnFloat64>()->Append(0); return;
|
|
219
|
+
case Type::String: col->As<ColumnString>()->Append(std::string_view()); return;
|
|
220
|
+
case Type::FixedString: col->As<ColumnFixedString>()->Append(std::string_view()); return;
|
|
221
|
+
case Type::Date: col->As<ColumnDate>()->Append(0); return;
|
|
222
|
+
case Type::Date32: col->As<ColumnDate32>()->Append(0); return;
|
|
223
|
+
case Type::DateTime: col->As<ColumnDateTime>()->Append(0); return;
|
|
224
|
+
case Type::DateTime64: col->As<ColumnDateTime64>()->Append(0); return;
|
|
225
|
+
case Type::Array: {
|
|
226
|
+
auto inner_type = type->As<ArrayType>()->GetItemType();
|
|
227
|
+
auto inner_col = CreateColumnByType(inner_type->GetName());
|
|
228
|
+
col->As<ColumnArray>()->AppendAsColumn(inner_col);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
default:
|
|
232
|
+
throw chn::EncoderFailure(
|
|
233
|
+
"no default value for Nullable(" + type->GetName() + ")");
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
static int64_t time_to_datetime64_ticks(VALUE value, size_t prec) {
|
|
238
|
+
VALUE to_i = rb_funcall(value, rb_intern("to_i"), 0);
|
|
239
|
+
VALUE nsec = rb_funcall(value, rb_intern("nsec"), 0);
|
|
240
|
+
int64_t sec = NUM2LL(to_i);
|
|
241
|
+
int64_t ns = NUM2LL(nsec);
|
|
242
|
+
int64_t total_ns = sec * 1'000'000'000LL + ns;
|
|
243
|
+
if (prec <= 9) return total_ns / pow10_i64(9 - prec);
|
|
244
|
+
return total_ns * pow10_i64(prec - 9);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
static void append_value(const ColumnRef& col, VALUE value) {
|
|
248
|
+
auto type = col->Type();
|
|
249
|
+
switch (type->GetCode()) {
|
|
250
|
+
case Type::Int8: col->As<ColumnInt8>()->Append(NUM2INT(value)); return;
|
|
251
|
+
case Type::Int16: col->As<ColumnInt16>()->Append(NUM2INT(value)); return;
|
|
252
|
+
case Type::Int32: col->As<ColumnInt32>()->Append(NUM2INT(value)); return;
|
|
253
|
+
case Type::Int64: col->As<ColumnInt64>()->Append(NUM2LL(value)); return;
|
|
254
|
+
case Type::UInt8: col->As<ColumnUInt8>()->Append(NUM2UINT(value)); return;
|
|
255
|
+
case Type::UInt16: col->As<ColumnUInt16>()->Append(NUM2UINT(value)); return;
|
|
256
|
+
case Type::UInt32: col->As<ColumnUInt32>()->Append(NUM2UINT(value)); return;
|
|
257
|
+
case Type::UInt64: col->As<ColumnUInt64>()->Append(NUM2ULL(value)); return;
|
|
258
|
+
case Type::Float32: col->As<ColumnFloat32>()->Append(static_cast<float>(NUM2DBL(value))); return;
|
|
259
|
+
case Type::Float64: col->As<ColumnFloat64>()->Append(NUM2DBL(value)); return;
|
|
260
|
+
|
|
261
|
+
case Type::String: {
|
|
262
|
+
StringValue(value);
|
|
263
|
+
col->As<ColumnString>()->Append(
|
|
264
|
+
std::string_view(RSTRING_PTR(value), RSTRING_LEN(value)));
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
case Type::FixedString: {
|
|
268
|
+
StringValue(value);
|
|
269
|
+
col->As<ColumnFixedString>()->Append(
|
|
270
|
+
std::string_view(RSTRING_PTR(value), RSTRING_LEN(value)));
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
case Type::Date: {
|
|
275
|
+
VALUE to_i = rb_funcall(value, rb_intern("to_i"), 0);
|
|
276
|
+
col->As<ColumnDate>()->Append(static_cast<std::time_t>(NUM2LL(to_i)));
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
case Type::Date32: {
|
|
280
|
+
VALUE to_i = rb_funcall(value, rb_intern("to_i"), 0);
|
|
281
|
+
col->As<ColumnDate32>()->Append(static_cast<std::time_t>(NUM2LL(to_i)));
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
case Type::DateTime: {
|
|
285
|
+
VALUE to_i = rb_funcall(value, rb_intern("to_i"), 0);
|
|
286
|
+
col->As<ColumnDateTime>()->Append(static_cast<std::time_t>(NUM2LL(to_i)));
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
case Type::DateTime64: {
|
|
290
|
+
size_t prec = type->As<DateTime64Type>()->GetPrecision();
|
|
291
|
+
col->As<ColumnDateTime64>()->Append(time_to_datetime64_ticks(value, prec));
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
case Type::Nullable: {
|
|
296
|
+
auto nul = col->As<ColumnNullable>();
|
|
297
|
+
auto nested = nul->Nested();
|
|
298
|
+
if (NIL_P(value)) {
|
|
299
|
+
nul->Append(true);
|
|
300
|
+
append_default(nested);
|
|
301
|
+
} else {
|
|
302
|
+
nul->Append(false);
|
|
303
|
+
append_value(nested, value);
|
|
304
|
+
}
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
case Type::Array: {
|
|
309
|
+
Check_Type(value, T_ARRAY);
|
|
310
|
+
auto inner_type = type->As<ArrayType>()->GetItemType();
|
|
311
|
+
auto inner_col = CreateColumnByType(inner_type->GetName());
|
|
312
|
+
if (!inner_col) {
|
|
313
|
+
throw chn::EncoderFailure(
|
|
314
|
+
"cannot create column for Array inner type " + inner_type->GetName());
|
|
315
|
+
}
|
|
316
|
+
long n = RARRAY_LEN(value);
|
|
317
|
+
for (long i = 0; i < n; i++) {
|
|
318
|
+
append_value(inner_col, rb_ary_entry(value, i));
|
|
319
|
+
}
|
|
320
|
+
col->As<ColumnArray>()->AppendAsColumn(inner_col);
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
default:
|
|
325
|
+
throw chn::EncoderFailure(
|
|
326
|
+
"cannot insert into column of type " + type->GetName());
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// ------------------------------------------------------------------
|
|
331
|
+
// Client (TypedData-wrapped Client*)
|
|
332
|
+
// ------------------------------------------------------------------
|
|
333
|
+
|
|
334
|
+
struct CHClient {
|
|
335
|
+
std::unique_ptr<Client> client;
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
static void ch_client_free(void* p) {
|
|
339
|
+
delete static_cast<CHClient*>(p);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
static size_t ch_client_size(const void* /*p*/) {
|
|
343
|
+
return sizeof(CHClient);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
static const rb_data_type_t ch_client_data_type = {
|
|
347
|
+
"ClickhouseNative::Client",
|
|
348
|
+
{ NULL, ch_client_free, ch_client_size, },
|
|
349
|
+
NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY,
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
static CHClient* as_client(VALUE self) {
|
|
353
|
+
CHClient* c;
|
|
354
|
+
TypedData_Get_Struct(self, CHClient, &ch_client_data_type, c);
|
|
355
|
+
return c;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
static VALUE ch_client_alloc(VALUE klass) {
|
|
359
|
+
auto* c = new CHClient;
|
|
360
|
+
return TypedData_Wrap_Struct(klass, &ch_client_data_type, c);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
static std::string kwarg_str(VALUE kwargs, const char* key, const char* fallback) {
|
|
364
|
+
ID id = rb_intern(key);
|
|
365
|
+
VALUE v = rb_hash_lookup2(kwargs, ID2SYM(id), Qundef);
|
|
366
|
+
if (v == Qundef || NIL_P(v)) return std::string(fallback);
|
|
367
|
+
return std::string(StringValueCStr(v));
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
static uint16_t kwarg_uint16(VALUE kwargs, const char* key, uint16_t fallback) {
|
|
371
|
+
ID id = rb_intern(key);
|
|
372
|
+
VALUE v = rb_hash_lookup2(kwargs, ID2SYM(id), Qundef);
|
|
373
|
+
if (v == Qundef || NIL_P(v)) return fallback;
|
|
374
|
+
return static_cast<uint16_t>(NUM2UINT(v));
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
static CompressionMethod kwarg_compression(VALUE kwargs) {
|
|
378
|
+
VALUE v = rb_hash_lookup2(kwargs, ID2SYM(rb_intern("compression")), Qundef);
|
|
379
|
+
if (v == Qundef || NIL_P(v)) return CompressionMethod::None;
|
|
380
|
+
ID sym = SYMBOL_P(v) ? SYM2ID(v) : rb_intern(StringValueCStr(v));
|
|
381
|
+
ID none_id = rb_intern("none");
|
|
382
|
+
ID lz4_id = rb_intern("lz4");
|
|
383
|
+
ID zstd_id = rb_intern("zstd");
|
|
384
|
+
if (sym == none_id) return CompressionMethod::None;
|
|
385
|
+
if (sym == lz4_id) return CompressionMethod::LZ4;
|
|
386
|
+
if (sym == zstd_id) return CompressionMethod::ZSTD;
|
|
387
|
+
rb_raise(rb_eArgError, "clickhouse-native: unknown compression %s (expected :none, :lz4, :zstd)",
|
|
388
|
+
rb_id2name(sym));
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// Client.new(host:, port:, database:, user:, password:)
|
|
392
|
+
static VALUE ch_client_initialize(int argc, VALUE* argv, VALUE self) {
|
|
393
|
+
VALUE kwargs = Qnil;
|
|
394
|
+
rb_scan_args(argc, argv, "0:", &kwargs);
|
|
395
|
+
if (NIL_P(kwargs)) kwargs = rb_hash_new();
|
|
396
|
+
|
|
397
|
+
std::string host = kwarg_str(kwargs, "host", "localhost");
|
|
398
|
+
uint16_t port = kwarg_uint16(kwargs, "port", 9000);
|
|
399
|
+
std::string database = kwarg_str(kwargs, "database", "default");
|
|
400
|
+
std::string user = kwarg_str(kwargs, "user", "default");
|
|
401
|
+
std::string password = kwarg_str(kwargs, "password", "");
|
|
402
|
+
CompressionMethod compression = kwarg_compression(kwargs);
|
|
403
|
+
|
|
404
|
+
CHClient* c = as_client(self);
|
|
405
|
+
try {
|
|
406
|
+
ClientOptions opts;
|
|
407
|
+
opts.SetHost(host).SetPort(port)
|
|
408
|
+
.SetDefaultDatabase(database).SetUser(user).SetPassword(password)
|
|
409
|
+
.SetCompressionMethod(compression);
|
|
410
|
+
c->client = std::make_unique<Client>(opts);
|
|
411
|
+
} catch (const std::exception& e) {
|
|
412
|
+
raise_mapped_ex(e);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
rb_ivar_set(self, rb_intern("@host"), rb_utf8_str_new(host.data(), host.size()));
|
|
416
|
+
rb_ivar_set(self, rb_intern("@port"), UINT2NUM(port));
|
|
417
|
+
rb_ivar_set(self, rb_intern("@database"), rb_utf8_str_new(database.data(), database.size()));
|
|
418
|
+
return self;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// ------------------------------------------------------------------
|
|
422
|
+
// GVL-released execute()
|
|
423
|
+
// ------------------------------------------------------------------
|
|
424
|
+
|
|
425
|
+
namespace {
|
|
426
|
+
struct ExecuteNoGVL {
|
|
427
|
+
Client* client;
|
|
428
|
+
std::string sql;
|
|
429
|
+
std::exception_ptr err;
|
|
430
|
+
};
|
|
431
|
+
} // namespace
|
|
432
|
+
|
|
433
|
+
static void* execute_no_gvl(void* data) {
|
|
434
|
+
auto* a = static_cast<ExecuteNoGVL*>(data);
|
|
435
|
+
try {
|
|
436
|
+
a->client->Execute(Query(a->sql));
|
|
437
|
+
} catch (...) {
|
|
438
|
+
a->err = std::current_exception();
|
|
439
|
+
}
|
|
440
|
+
return nullptr;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
static void execute_unblock(void* data) {
|
|
444
|
+
// The only safe abort clickhouse-cpp exposes is tearing the connection.
|
|
445
|
+
// On interrupt we kill the socket; the pool will discard this client.
|
|
446
|
+
auto* a = static_cast<ExecuteNoGVL*>(data);
|
|
447
|
+
try { a->client->ResetConnection(); } catch (...) {}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
static VALUE ch_client_execute(VALUE self, VALUE rb_sql) {
|
|
451
|
+
Check_Type(rb_sql, T_STRING);
|
|
452
|
+
CHClient* c = as_client(self);
|
|
453
|
+
if (!c->client) rb_raise(err_connection, "clickhouse-native: client is closed");
|
|
454
|
+
|
|
455
|
+
ExecuteNoGVL args{c->client.get(), std::string(StringValueCStr(rb_sql)), nullptr};
|
|
456
|
+
rb_thread_call_without_gvl(execute_no_gvl, &args, execute_unblock, &args);
|
|
457
|
+
if (args.err) {
|
|
458
|
+
// clickhouse-cpp may leave the read stream partially consumed when the
|
|
459
|
+
// server exception or an unsupported-type error is thrown mid-block.
|
|
460
|
+
// Reset so the next call on this Client starts from a clean protocol.
|
|
461
|
+
try { c->client->ResetConnection(); } catch (...) {}
|
|
462
|
+
try { std::rethrow_exception(args.err); }
|
|
463
|
+
catch (const std::exception& e) { raise_mapped_ex(e); }
|
|
464
|
+
}
|
|
465
|
+
return Qnil;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
// ------------------------------------------------------------------
|
|
469
|
+
// query() — synchronous, GVL held (streaming query_each comes in Week 5)
|
|
470
|
+
// ------------------------------------------------------------------
|
|
471
|
+
|
|
472
|
+
static VALUE ch_client_query(VALUE self, VALUE rb_sql) {
|
|
473
|
+
Check_Type(rb_sql, T_STRING);
|
|
474
|
+
CHClient* c = as_client(self);
|
|
475
|
+
if (!c->client) rb_raise(err_connection, "clickhouse-native: client is closed");
|
|
476
|
+
|
|
477
|
+
std::string sql(StringValueCStr(rb_sql));
|
|
478
|
+
VALUE rows = rb_ary_new();
|
|
479
|
+
try {
|
|
480
|
+
std::vector<ID> col_ids;
|
|
481
|
+
c->client->Select(sql, [&](const Block& block) {
|
|
482
|
+
size_t ncols = block.GetColumnCount();
|
|
483
|
+
size_t nrows = block.GetRowCount();
|
|
484
|
+
if (nrows == 0) return;
|
|
485
|
+
if (col_ids.empty()) {
|
|
486
|
+
col_ids.reserve(ncols);
|
|
487
|
+
for (size_t i = 0; i < ncols; i++) {
|
|
488
|
+
const std::string& name = block.GetColumnName(i);
|
|
489
|
+
col_ids.push_back(rb_intern2(name.data(), name.size()));
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
for (size_t r = 0; r < nrows; r++) {
|
|
493
|
+
VALUE h = rb_hash_new();
|
|
494
|
+
for (size_t cc = 0; cc < ncols; cc++) {
|
|
495
|
+
rb_hash_aset(h, ID2SYM(col_ids[cc]), value_at(block[cc], r));
|
|
496
|
+
}
|
|
497
|
+
rb_ary_push(rows, h);
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
return rows;
|
|
501
|
+
} catch (const std::exception& e) {
|
|
502
|
+
try { c->client->ResetConnection(); } catch (...) {}
|
|
503
|
+
raise_mapped_ex(e);
|
|
504
|
+
}
|
|
505
|
+
return Qnil;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
// ------------------------------------------------------------------
|
|
509
|
+
// query_value — returns the first cell of the first row, or nil
|
|
510
|
+
// ------------------------------------------------------------------
|
|
511
|
+
|
|
512
|
+
static VALUE ch_client_query_value(VALUE self, VALUE rb_sql) {
|
|
513
|
+
Check_Type(rb_sql, T_STRING);
|
|
514
|
+
CHClient* c = as_client(self);
|
|
515
|
+
if (!c->client) rb_raise(err_connection, "clickhouse-native: client is closed");
|
|
516
|
+
|
|
517
|
+
std::string sql(StringValueCStr(rb_sql));
|
|
518
|
+
try {
|
|
519
|
+
VALUE out = Qnil;
|
|
520
|
+
bool seen = false;
|
|
521
|
+
c->client->Select(sql, [&](const Block& block) {
|
|
522
|
+
if (seen) return;
|
|
523
|
+
if (block.GetRowCount() == 0 || block.GetColumnCount() == 0) return;
|
|
524
|
+
out = value_at(block[0], 0);
|
|
525
|
+
seen = true;
|
|
526
|
+
});
|
|
527
|
+
return out;
|
|
528
|
+
} catch (const std::exception& e) {
|
|
529
|
+
try { c->client->ResetConnection(); } catch (...) {}
|
|
530
|
+
raise_mapped_ex(e);
|
|
531
|
+
}
|
|
532
|
+
return Qnil;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
// ------------------------------------------------------------------
|
|
536
|
+
// insert_block(table, [[name, type], ...], [[v, v, ...], ...])
|
|
537
|
+
// ------------------------------------------------------------------
|
|
538
|
+
|
|
539
|
+
namespace {
|
|
540
|
+
struct InsertNoGVL {
|
|
541
|
+
Client* client;
|
|
542
|
+
const std::string* table;
|
|
543
|
+
const Block* block;
|
|
544
|
+
std::exception_ptr err;
|
|
545
|
+
};
|
|
546
|
+
} // namespace
|
|
547
|
+
|
|
548
|
+
static void* insert_no_gvl(void* data) {
|
|
549
|
+
auto* a = static_cast<InsertNoGVL*>(data);
|
|
550
|
+
try {
|
|
551
|
+
a->client->Insert(*a->table, *a->block);
|
|
552
|
+
} catch (...) {
|
|
553
|
+
a->err = std::current_exception();
|
|
554
|
+
}
|
|
555
|
+
return nullptr;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
static void insert_unblock(void* data) {
|
|
559
|
+
auto* a = static_cast<InsertNoGVL*>(data);
|
|
560
|
+
try { a->client->ResetConnection(); } catch (...) {}
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
static VALUE ch_client_insert_block(VALUE self, VALUE rb_table, VALUE rb_columns, VALUE rb_rows) {
|
|
564
|
+
Check_Type(rb_table, T_STRING);
|
|
565
|
+
Check_Type(rb_columns, T_ARRAY);
|
|
566
|
+
Check_Type(rb_rows, T_ARRAY);
|
|
567
|
+
CHClient* c = as_client(self);
|
|
568
|
+
if (!c->client) rb_raise(err_connection, "clickhouse-native: client is closed");
|
|
569
|
+
|
|
570
|
+
long ncols = RARRAY_LEN(rb_columns);
|
|
571
|
+
long nrows = RARRAY_LEN(rb_rows);
|
|
572
|
+
if (ncols == 0) rb_raise(err_encoder, "clickhouse-native: insert requires at least one column");
|
|
573
|
+
|
|
574
|
+
try {
|
|
575
|
+
std::string table(RSTRING_PTR(rb_table), RSTRING_LEN(rb_table));
|
|
576
|
+
std::vector<std::string> names;
|
|
577
|
+
std::vector<ColumnRef> cols;
|
|
578
|
+
names.reserve(ncols);
|
|
579
|
+
cols.reserve(ncols);
|
|
580
|
+
for (long i = 0; i < ncols; i++) {
|
|
581
|
+
VALUE pair = rb_ary_entry(rb_columns, i);
|
|
582
|
+
Check_Type(pair, T_ARRAY);
|
|
583
|
+
VALUE rb_name = rb_ary_entry(pair, 0);
|
|
584
|
+
VALUE rb_type = rb_ary_entry(pair, 1);
|
|
585
|
+
StringValue(rb_name);
|
|
586
|
+
StringValue(rb_type);
|
|
587
|
+
names.emplace_back(RSTRING_PTR(rb_name), RSTRING_LEN(rb_name));
|
|
588
|
+
std::string type_str(RSTRING_PTR(rb_type), RSTRING_LEN(rb_type));
|
|
589
|
+
auto ch_col = CreateColumnByType(type_str);
|
|
590
|
+
if (!ch_col) {
|
|
591
|
+
throw chn::EncoderFailure("unknown column type " + type_str + " for " + names.back());
|
|
592
|
+
}
|
|
593
|
+
ch_col->Reserve(static_cast<size_t>(nrows));
|
|
594
|
+
cols.push_back(ch_col);
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
for (long r = 0; r < nrows; r++) {
|
|
598
|
+
VALUE row = rb_ary_entry(rb_rows, r);
|
|
599
|
+
Check_Type(row, T_ARRAY);
|
|
600
|
+
if (RARRAY_LEN(row) != ncols) {
|
|
601
|
+
char msg[96];
|
|
602
|
+
std::snprintf(msg, sizeof(msg),
|
|
603
|
+
"row %ld has %ld values, expected %ld",
|
|
604
|
+
r, static_cast<long>(RARRAY_LEN(row)), ncols);
|
|
605
|
+
throw chn::EncoderFailure(msg);
|
|
606
|
+
}
|
|
607
|
+
for (long cc = 0; cc < ncols; cc++) {
|
|
608
|
+
append_value(cols[cc], rb_ary_entry(row, cc));
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
Block block;
|
|
613
|
+
for (long i = 0; i < ncols; i++) {
|
|
614
|
+
block.AppendColumn(names[i], cols[i]);
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
InsertNoGVL args{c->client.get(), &table, &block, nullptr};
|
|
618
|
+
rb_thread_call_without_gvl(insert_no_gvl, &args, insert_unblock, &args);
|
|
619
|
+
if (args.err) {
|
|
620
|
+
try { c->client->ResetConnection(); } catch (...) {}
|
|
621
|
+
try { std::rethrow_exception(args.err); }
|
|
622
|
+
catch (const std::exception& e) { raise_mapped_ex(e); }
|
|
623
|
+
}
|
|
624
|
+
} catch (const std::exception& e) {
|
|
625
|
+
try { c->client->ResetConnection(); } catch (...) {}
|
|
626
|
+
raise_mapped_ex(e);
|
|
627
|
+
}
|
|
628
|
+
return LONG2NUM(nrows);
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
// ------------------------------------------------------------------
|
|
632
|
+
// query_each(sql) { |row_hash| ... }
|
|
633
|
+
// ------------------------------------------------------------------
|
|
634
|
+
|
|
635
|
+
namespace {
|
|
636
|
+
struct QueryEachState {
|
|
637
|
+
VALUE user_proc;
|
|
638
|
+
std::vector<ID> col_ids;
|
|
639
|
+
int exc_tag;
|
|
640
|
+
bool aborted;
|
|
641
|
+
};
|
|
642
|
+
|
|
643
|
+
struct YieldBlockArgs {
|
|
644
|
+
const Block* block;
|
|
645
|
+
QueryEachState* state;
|
|
646
|
+
};
|
|
647
|
+
|
|
648
|
+
struct QueryEachNoGVL {
|
|
649
|
+
Client* client;
|
|
650
|
+
std::string sql;
|
|
651
|
+
QueryEachState* state;
|
|
652
|
+
std::exception_ptr err;
|
|
653
|
+
};
|
|
654
|
+
} // namespace
|
|
655
|
+
|
|
656
|
+
static VALUE yield_rows_body(VALUE arg) {
|
|
657
|
+
auto* args = reinterpret_cast<YieldBlockArgs*>(arg);
|
|
658
|
+
const Block& block = *args->block;
|
|
659
|
+
auto* state = args->state;
|
|
660
|
+
size_t ncols = block.GetColumnCount();
|
|
661
|
+
size_t nrows = block.GetRowCount();
|
|
662
|
+
if (nrows == 0) return Qnil;
|
|
663
|
+
if (state->col_ids.empty() && ncols > 0) {
|
|
664
|
+
state->col_ids.reserve(ncols);
|
|
665
|
+
for (size_t i = 0; i < ncols; i++) {
|
|
666
|
+
const std::string& name = block.GetColumnName(i);
|
|
667
|
+
state->col_ids.push_back(rb_intern2(name.data(), name.size()));
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
for (size_t r = 0; r < nrows; r++) {
|
|
671
|
+
VALUE h = rb_hash_new();
|
|
672
|
+
for (size_t cc = 0; cc < ncols; cc++) {
|
|
673
|
+
rb_hash_aset(h, ID2SYM(state->col_ids[cc]), value_at(block[cc], r));
|
|
674
|
+
}
|
|
675
|
+
rb_funcall(state->user_proc, rb_intern("call"), 1, h);
|
|
676
|
+
}
|
|
677
|
+
return Qnil;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
static void* with_gvl_yield(void* data) {
|
|
681
|
+
auto* args = static_cast<YieldBlockArgs*>(data);
|
|
682
|
+
int tag = 0;
|
|
683
|
+
rb_protect(yield_rows_body, reinterpret_cast<VALUE>(args), &tag);
|
|
684
|
+
if (tag != 0) {
|
|
685
|
+
args->state->exc_tag = tag;
|
|
686
|
+
args->state->aborted = true;
|
|
687
|
+
}
|
|
688
|
+
return nullptr;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
static void* query_each_no_gvl(void* data) {
|
|
692
|
+
auto* a = static_cast<QueryEachNoGVL*>(data);
|
|
693
|
+
try {
|
|
694
|
+
a->client->SelectCancelable(a->sql, [&](const Block& block) -> bool {
|
|
695
|
+
if (a->state->aborted) return false;
|
|
696
|
+
YieldBlockArgs ya{&block, a->state};
|
|
697
|
+
rb_thread_call_with_gvl(with_gvl_yield, &ya);
|
|
698
|
+
return !a->state->aborted;
|
|
699
|
+
});
|
|
700
|
+
} catch (...) {
|
|
701
|
+
a->err = std::current_exception();
|
|
702
|
+
}
|
|
703
|
+
return nullptr;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
static void query_each_unblock(void* data) {
|
|
707
|
+
auto* a = static_cast<QueryEachNoGVL*>(data);
|
|
708
|
+
a->state->aborted = true;
|
|
709
|
+
try { a->client->ResetConnection(); } catch (...) {}
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
static VALUE ch_client_query_each(VALUE self, VALUE rb_sql) {
|
|
713
|
+
rb_need_block();
|
|
714
|
+
Check_Type(rb_sql, T_STRING);
|
|
715
|
+
CHClient* c = as_client(self);
|
|
716
|
+
if (!c->client) rb_raise(err_connection, "clickhouse-native: client is closed");
|
|
717
|
+
|
|
718
|
+
QueryEachState state{rb_block_proc(), {}, 0, false};
|
|
719
|
+
QueryEachNoGVL args{
|
|
720
|
+
c->client.get(),
|
|
721
|
+
std::string(RSTRING_PTR(rb_sql), RSTRING_LEN(rb_sql)),
|
|
722
|
+
&state,
|
|
723
|
+
nullptr,
|
|
724
|
+
};
|
|
725
|
+
|
|
726
|
+
rb_thread_call_without_gvl(query_each_no_gvl, &args, query_each_unblock, &args);
|
|
727
|
+
|
|
728
|
+
if (args.err) {
|
|
729
|
+
try { c->client->ResetConnection(); } catch (...) {}
|
|
730
|
+
if (state.exc_tag) rb_jump_tag(state.exc_tag);
|
|
731
|
+
try { std::rethrow_exception(args.err); }
|
|
732
|
+
catch (const std::exception& e) { raise_mapped_ex(e); }
|
|
733
|
+
}
|
|
734
|
+
if (state.exc_tag) {
|
|
735
|
+
try { c->client->ResetConnection(); } catch (...) {}
|
|
736
|
+
rb_jump_tag(state.exc_tag);
|
|
737
|
+
}
|
|
738
|
+
return self;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
// ------------------------------------------------------------------
|
|
742
|
+
// ping / server_version / reset_connection / close
|
|
743
|
+
// ------------------------------------------------------------------
|
|
744
|
+
|
|
745
|
+
namespace {
|
|
746
|
+
struct PingNoGVL {
|
|
747
|
+
Client* client;
|
|
748
|
+
std::exception_ptr err;
|
|
749
|
+
};
|
|
750
|
+
} // namespace
|
|
751
|
+
|
|
752
|
+
static void* ping_no_gvl(void* data) {
|
|
753
|
+
auto* a = static_cast<PingNoGVL*>(data);
|
|
754
|
+
try { a->client->Ping(); } catch (...) { a->err = std::current_exception(); }
|
|
755
|
+
return nullptr;
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
static VALUE ch_client_ping(VALUE self) {
|
|
759
|
+
CHClient* c = as_client(self);
|
|
760
|
+
if (!c->client) rb_raise(err_connection, "clickhouse-native: client is closed");
|
|
761
|
+
PingNoGVL args{c->client.get(), nullptr};
|
|
762
|
+
rb_thread_call_without_gvl(ping_no_gvl, &args, nullptr, nullptr);
|
|
763
|
+
if (args.err) {
|
|
764
|
+
try { std::rethrow_exception(args.err); }
|
|
765
|
+
catch (const std::exception& e) { raise_mapped_ex(e); }
|
|
766
|
+
}
|
|
767
|
+
return Qtrue;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
static VALUE ch_client_server_version(VALUE self) {
|
|
771
|
+
CHClient* c = as_client(self);
|
|
772
|
+
if (!c->client) rb_raise(err_connection, "clickhouse-native: client is closed");
|
|
773
|
+
try {
|
|
774
|
+
const ServerInfo& info = c->client->GetServerInfo();
|
|
775
|
+
char buf[64];
|
|
776
|
+
int n = snprintf(buf, sizeof(buf), "%llu.%llu.%llu",
|
|
777
|
+
static_cast<unsigned long long>(info.version_major),
|
|
778
|
+
static_cast<unsigned long long>(info.version_minor),
|
|
779
|
+
static_cast<unsigned long long>(info.version_patch));
|
|
780
|
+
return rb_utf8_str_new(buf, n);
|
|
781
|
+
} catch (const std::exception& e) {
|
|
782
|
+
raise_mapped_ex(e);
|
|
783
|
+
}
|
|
784
|
+
return Qnil;
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
static VALUE ch_client_reset_connection(VALUE self) {
|
|
788
|
+
CHClient* c = as_client(self);
|
|
789
|
+
if (!c->client) return Qnil;
|
|
790
|
+
try { c->client->ResetConnection(); } catch (...) {}
|
|
791
|
+
return Qtrue;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
static VALUE ch_client_close(VALUE self) {
|
|
795
|
+
CHClient* c = as_client(self);
|
|
796
|
+
c->client.reset();
|
|
797
|
+
return Qnil;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
// ------------------------------------------------------------------
|
|
801
|
+
// Init
|
|
802
|
+
// ------------------------------------------------------------------
|
|
803
|
+
|
|
804
|
+
extern "C" void Init_clickhouse_native(void) {
|
|
805
|
+
rb_mClickhouseNative = rb_define_module("ClickhouseNative");
|
|
806
|
+
|
|
807
|
+
err_base = rb_const_get(rb_mClickhouseNative, rb_intern("Error"));
|
|
808
|
+
err_connection = rb_const_get(rb_mClickhouseNative, rb_intern("ConnectionError"));
|
|
809
|
+
err_timeout = rb_const_get(rb_mClickhouseNative, rb_intern("TimeoutError"));
|
|
810
|
+
err_protocol = rb_const_get(rb_mClickhouseNative, rb_intern("ProtocolError"));
|
|
811
|
+
err_server = rb_const_get(rb_mClickhouseNative, rb_intern("ServerError"));
|
|
812
|
+
err_encoder = rb_const_get(rb_mClickhouseNative, rb_intern("EncoderError"));
|
|
813
|
+
err_decoder = rb_const_get(rb_mClickhouseNative, rb_intern("DecoderError"));
|
|
814
|
+
err_unsupported = rb_const_get(rb_mClickhouseNative, rb_intern("UnsupportedTypeError"));
|
|
815
|
+
rb_global_variable(&err_base);
|
|
816
|
+
rb_global_variable(&err_connection);
|
|
817
|
+
rb_global_variable(&err_timeout);
|
|
818
|
+
rb_global_variable(&err_protocol);
|
|
819
|
+
rb_global_variable(&err_server);
|
|
820
|
+
rb_global_variable(&err_encoder);
|
|
821
|
+
rb_global_variable(&err_decoder);
|
|
822
|
+
rb_global_variable(&err_unsupported);
|
|
823
|
+
|
|
824
|
+
rb_cClient = rb_define_class_under(rb_mClickhouseNative, "Client", rb_cObject);
|
|
825
|
+
rb_global_variable(&rb_cClient);
|
|
826
|
+
rb_define_alloc_func(rb_cClient, ch_client_alloc);
|
|
827
|
+
rb_define_method(rb_cClient, "initialize",
|
|
828
|
+
reinterpret_cast<VALUE (*)(ANYARGS)>(ch_client_initialize), -1);
|
|
829
|
+
rb_define_method(rb_cClient, "execute",
|
|
830
|
+
reinterpret_cast<VALUE (*)(ANYARGS)>(ch_client_execute), 1);
|
|
831
|
+
rb_define_method(rb_cClient, "query",
|
|
832
|
+
reinterpret_cast<VALUE (*)(ANYARGS)>(ch_client_query), 1);
|
|
833
|
+
rb_define_method(rb_cClient, "query_value",
|
|
834
|
+
reinterpret_cast<VALUE (*)(ANYARGS)>(ch_client_query_value), 1);
|
|
835
|
+
rb_define_method(rb_cClient, "query_each",
|
|
836
|
+
reinterpret_cast<VALUE (*)(ANYARGS)>(ch_client_query_each), 1);
|
|
837
|
+
rb_define_method(rb_cClient, "insert_block",
|
|
838
|
+
reinterpret_cast<VALUE (*)(ANYARGS)>(ch_client_insert_block), 3);
|
|
839
|
+
rb_define_method(rb_cClient, "ping",
|
|
840
|
+
reinterpret_cast<VALUE (*)(ANYARGS)>(ch_client_ping), 0);
|
|
841
|
+
rb_define_method(rb_cClient, "server_version",
|
|
842
|
+
reinterpret_cast<VALUE (*)(ANYARGS)>(ch_client_server_version), 0);
|
|
843
|
+
rb_define_method(rb_cClient, "reset_connection",
|
|
844
|
+
reinterpret_cast<VALUE (*)(ANYARGS)>(ch_client_reset_connection), 0);
|
|
845
|
+
rb_define_method(rb_cClient, "close",
|
|
846
|
+
reinterpret_cast<VALUE (*)(ANYARGS)>(ch_client_close), 0);
|
|
847
|
+
}
|