diff --git a/.github/workflows/_extension_distribution.yml b/.github/workflows/_extension_distribution.yml index 8bcf9ac3..8bbd392e 100644 --- a/.github/workflows/_extension_distribution.yml +++ b/.github/workflows/_extension_distribution.yml @@ -45,7 +45,37 @@ on: required: false type: boolean default: true - + # Supply an override repository to build, instead of using the current one + override_repository: + required: false + type: string + default: "" + # The git ref used for the override_repository + override_ref: + required: false + type: string + default: "" + # Override the repo for the CI tools (for testing CI tools itself) + override_ci_tools_repository: + required: false + type: string + default: "" + # Override the ref for the CI tools (for testing CI tools itself) + override_ci_tools_ref: + required: false + type: string + default: "" + # Pass extra toolchains + # available: (rust) + extra_toolchains: + required: false + type: string + default: "" + # DEPRECATED: use extra_toolchains instead + enable_rust: + required: false + type: boolean + default: false jobs: generate_matrix: name: Generate matrix @@ -57,6 +87,17 @@ jobs: wasm_matrix: ${{ steps.set-matrix-wasm.outputs.wasm_matrix }} steps: - uses: actions/checkout@v3 + name: Checkout override repository + if: ${{inputs.override_repository != ''}} + with: + repository: ${{ inputs.override_repository }} + ref: ${{ inputs.override_ref }} + fetch-depth: 0 + submodules: 'true' + + - uses: actions/checkout@v3 + name: Checkout current repository + if: ${{inputs.override_repository == ''}} with: fetch-depth: 0 submodules: 'true' @@ -108,19 +149,32 @@ jobs: env: VCPKG_TARGET_TRIPLET: ${{ matrix.vcpkg_triplet }} VCPKG_TOOLCHAIN_PATH: ${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake - GEN: Ninja + GEN: ninja BUILD_SHELL: ${{ inputs.build_duckdb_shell && '1' || '0' }} DUCKDB_PLATFORM: ${{ matrix.duckdb_arch }} + ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true steps: + ### + # Setup environment (TODO: this should ideally be part of a container image) + ### - name: Install required ubuntu packages if: ${{ matrix.duckdb_arch == 'linux_amd64' || matrix.duckdb_arch == 'linux_arm64' }} run: | apt-get update -y -qq apt-get install -y -qq software-properties-common - add-apt-repository ppa:git-core/ppa - apt-get update -y -qq - apt-get install -y -qq ninja-build make gcc-multilib g++-multilib libssl-dev wget openjdk-8-jdk zip maven unixodbc-dev libc6-dev-i386 lib32readline6-dev libssl-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip build-essential checkinstall libffi-dev curl libz-dev openssh-client + apt-get install -y -qq --fix-missing ninja-build make gcc-multilib g++-multilib libssl-dev wget openjdk-8-jdk zip maven unixodbc-dev libc6-dev-i386 lib32readline6-dev libssl-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip build-essential checkinstall libffi-dev curl libz-dev openssh-client pkg-config + + - name: Install required manylinux packages + if: ${{ matrix.duckdb_arch == 'linux_amd64_gcc4' }} + run: | + yum install -y epel-release -y pkgconfig + + - name: Install cross compiler for linux_arm64 + shell: bash + if: ${{ matrix.duckdb_arch == 'linux_arm64' }} + run: | + apt-get install -y -qq gcc-aarch64-linux-gnu g++-aarch64-linux-gnu - name: Install Git 2.18.5 if: ${{ matrix.duckdb_arch == 'linux_amd64' || matrix.duckdb_arch == 'linux_arm64' }} @@ -132,7 +186,56 @@ jobs: make prefix=/usr install git --version + - name: Setup Rust + if: ${{ (inputs.enable_rust || contains(format(';{0};', inputs.extra_toolchains), ';rust;')) && matrix.duckdb_arch == 'linux_amd64'}} + uses: dtolnay/rust-toolchain@stable + + - name: Setup Rust for cross compilation + if: ${{ (inputs.enable_rust || contains(format(';{0};', inputs.extra_toolchains), ';rust;')) && matrix.duckdb_arch == 'linux_arm64'}} + uses: dtolnay/rust-toolchain@stable + with: + targets: aarch64-unknown-linux-gnu + + - name: Setup Rust for manylinux (dtolnay/rust-toolchain doesn't work due to curl being old here) + if: ${{ (inputs.enable_rust || contains(format(';{0};', inputs.extra_toolchains), ';rust;')) && matrix.duckdb_arch == 'linux_amd64_gcc4' }} + run: | + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y + echo "$HOME/.cargo/bin" >> $GITHUB_PATH + + - name: Install CMake 3.21 + if: ${{ matrix.duckdb_arch == 'linux_amd64' || matrix.duckdb_arch == 'linux_arm64' }} + shell: bash + run: | + wget https://github.com/Kitware/CMake/releases/download/v3.21.3/cmake-3.21.3-linux-x86_64.sh + chmod +x cmake-3.21.3-linux-x86_64.sh + ./cmake-3.21.3-linux-x86_64.sh --skip-license --prefix=/usr/local + cmake --version + + - name: Install parser tools + if: ${{ contains(format(';{0};', inputs.extra_toolchains), ';parser_tools;') && (matrix.duckdb_arch == 'linux_amd64' || matrix.duckdb_arch == 'linux_arm64') }} + run: | + apt-get install -y -qq bison flex + + - name: Install parser tools (manylinux) + if: ${{ contains(format(';{0};', inputs.extra_toolchains), ';parser_tools;') && matrix.duckdb_arch == 'linux_amd64_gcc4'}} + run: | + yum install -y bison flex + + ### + # Checkin out repositories + ### + - uses: actions/checkout@v3 + name: Checkout override repository + if: ${{inputs.override_repository != ''}} + with: + repository: ${{ inputs.override_repository }} + ref: ${{ inputs.override_ref }} + fetch-depth: 0 + submodules: 'true' + - uses: actions/checkout@v3 + name: Checkout current repository + if: ${{inputs.override_repository == ''}} with: fetch-depth: 0 submodules: 'true' @@ -145,25 +248,41 @@ jobs: - name: Setup ManyLinux2014 if: ${{ matrix.duckdb_arch == 'linux_amd64_gcc4' }} run: | - ./duckdb/scripts/setup_manylinux2014.sh general aws-cli ccache ssh python_alias openssl + ./duckdb/scripts/setup_manylinux2014.sh general ccache ssh python_alias openssl + - uses: actions/checkout@v3 + name: Checkout Extension CI tools + if: ${{inputs.override_ci_tools_ref != ''}} + with: + path: 'extension-ci-tools' + ref: ${{ inputs.override_ci_tools_ref }} + repository: ${{ inputs.override_ci_tools_repository }} + fetch-depth: 0 + + ### + # Runtime configuration before build + ### - name: Setup Ccache uses: hendrikmuhs/ccache-action@v1.2.11 # Note: pinned due to GLIBC incompatibility in later releases continue-on-error: true with: key: ${{ github.job }}-${{ matrix.duckdb_arch }} - - name: Setup Ubuntu - if: ${{ matrix.duckdb_arch == 'linux_amd64' || matrix.duckdb_arch == 'linux_arm64' }} - uses: ./duckdb/.github/actions/ubuntu_18_setup - with: - aarch64_cross_compile: ${{ matrix.duckdb_arch == 'linux_arm64' && 1 }} - - name: Setup vcpkg uses: lukka/run-vcpkg@v11.1 with: vcpkgGitCommitId: ${{ inputs.vcpkg_commit }} + - name: Configure OpenSSL for Rust + if: ${{ (inputs.enable_rust || contains(format(';{0};', inputs.extra_toolchains), ';rust;')) }} + run: | + echo "OPENSSL_ROOT_DIR=`pwd`/build/release/vcpkg_installed/${{ matrix.vcpkg_triplet }}" >> $GITHUB_ENV + echo "OPENSSL_DIR=`pwd`/build/release/vcpkg_installed/${{ matrix.vcpkg_triplet }}" >> $GITHUB_ENV + echo "OPENSSL_USE_STATIC_LIBS=true" >> $GITHUB_ENV + + ### + # Building & testing + ### - name: Build extension env: GEN: ninja @@ -178,9 +297,8 @@ jobs: run: | make test - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v2 with: - if-no-files-found: error name: ${{ inputs.extension_name }}-${{ inputs.duckdb_version }}-extension-${{matrix.duckdb_arch}}${{inputs.artifact_postfix}} path: | build/release/extension/${{ inputs.extension_name }}/${{ inputs.extension_name }}.duckdb_extension @@ -196,12 +314,23 @@ jobs: VCPKG_TOOLCHAIN_PATH: ${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake VCPKG_TARGET_TRIPLET: ${{ matrix.vcpkg_triplet }} OSX_BUILD_ARCH: ${{ matrix.osx_build_arch }} - GEN: Ninja + GEN: ninja BUILD_SHELL: ${{ inputs.build_duckdb_shell && '1' || '0' }} DUCKDB_PLATFORM: ${{ matrix.duckdb_arch }} steps: - uses: actions/checkout@v3 + name: Checkout override repository + if: ${{inputs.override_repository != ''}} + with: + repository: ${{ inputs.override_repository }} + ref: ${{ inputs.override_ref }} + fetch-depth: 0 + submodules: 'true' + + - uses: actions/checkout@v3 + name: Checkout current repository + if: ${{inputs.override_repository == ''}} with: fetch-depth: 0 submodules: 'true' @@ -220,6 +349,15 @@ jobs: with: python-version: '3.11' + - uses: actions/checkout@v3 + name: Checkout Extension CI tools + if: ${{inputs.override_ci_tools_ref != ''}} + with: + path: 'extension-ci-tools' + ref: ${{ inputs.override_ci_tools_ref }} + repository: ${{ inputs.override_ci_tools_repository }} + fetch-depth: 0 + - name: Checkout DuckDB to version run: | cd duckdb @@ -230,6 +368,16 @@ jobs: with: vcpkgGitCommitId: ${{ inputs.vcpkg_commit }} + - name: Install Rust cross compile dependency + if: ${{ (inputs.enable_rust || contains(format(';{0};', inputs.extra_toolchains), ';rust;')) && matrix.osx_build_arch == 'x86_64'}} + run: | + rustup target add x86_64-apple-darwin + + - name: Install parser tools + if: ${{ contains(format(';{0};', inputs.extra_toolchains), ';parser_tools;')}} + run: | + brew install bison flex + - name: Build extension shell: bash env: @@ -258,7 +406,6 @@ jobs: strategy: matrix: ${{fromJson(needs.generate_matrix.outputs.windows_matrix)}} env: - GEN: Ninja VCPKG_TOOLCHAIN_PATH: ${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake VCPKG_TARGET_TRIPLET: ${{ matrix.vcpkg_triplet }} BUILD_SHELL: ${{ inputs.build_duckdb_shell && '1' || '0' }} @@ -274,6 +421,17 @@ jobs: git config --global core.eol lf - uses: actions/checkout@v3 + name: Checkout override repository + if: ${{inputs.override_repository != ''}} + with: + repository: ${{ inputs.override_repository }} + ref: ${{ inputs.override_ref }} + fetch-depth: 0 + submodules: 'true' + + - uses: actions/checkout@v3 + name: Checkout current repository + if: ${{inputs.override_repository == ''}} with: fetch-depth: 0 submodules: 'true' @@ -282,6 +440,15 @@ jobs: with: python-version: '3.11' + - name: Setup Rust + if: (inputs.enable_rust || contains(format(';{0};', inputs.extra_toolchains), ';rust;')) + uses: dtolnay/rust-toolchain@stable + + - name: Install parser tools + if: ${{ contains(format(';{0};', inputs.extra_toolchains), ';parser_tools;')}} + run: | + choco install winflexbison3 + - uses: r-lib/actions/setup-r@v2 if: matrix.duckdb_arch == 'windows_amd64_rtools' with: @@ -289,6 +456,15 @@ jobs: update-rtools: true rtools-version: '42' # linker bug in 43 + - uses: actions/checkout@v3 + name: Checkout Extension CI tools + if: ${{inputs.override_ci_tools_ref != ''}} + with: + path: 'extension-ci-tools' + ref: ${{ inputs.override_ci_tools_ref }} + repository: ${{ inputs.override_ci_tools_repository }} + fetch-depth: 0 + - name: Checkout DuckDB to version run: | cd duckdb @@ -305,19 +481,8 @@ jobs: with: vcpkgGitCommitId: ${{ inputs.vcpkg_commit }} - - name: Fix for MSVC issue - shell: bash - env: - OVERLAY_TRIPLET_SRC: ${{ github.workspace }}/vcpkg/triplets/community/x64-windows-static-md.cmake - OVERLAY_TRIPLET_DST: ${{ github.workspace }}/overlay_triplets/x64-windows-static-md.cmake - run: | - mkdir overlay_triplets - cp $OVERLAY_TRIPLET_SRC $OVERLAY_TRIPLET_DST - echo "set(VCPKG_PLATFORM_TOOLSET_VERSION "14.39")" >> $OVERLAY_TRIPLET_DST - - name: Build & test extension env: - VCPKG_OVERLAY_TRIPLETS: "${{ github.workspace }}/overlay_triplets" DUCKDB_PLATFORM: ${{ matrix.duckdb_arch }} DUCKDB_PLATFORM_RTOOLS: ${{ matrix.duckdb_arch == 'windows_amd64_rtools' && 1 || 0 }} run: | @@ -340,15 +505,34 @@ jobs: env: VCPKG_TARGET_TRIPLET: ${{ matrix.vcpkg_triplet }} VCPKG_TOOLCHAIN_PATH: ${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake - GEN: Ninja DUCKDB_PLATFORM: ${{ matrix.duckdb_arch }} steps: - uses: actions/checkout@v3 + name: Checkout override repository + if: ${{inputs.override_repository != ''}} + with: + repository: ${{ inputs.override_repository }} + ref: ${{ inputs.override_ref }} + fetch-depth: 0 + submodules: 'true' + + - uses: actions/checkout@v3 + name: Checkout current repository + if: ${{inputs.override_repository == ''}} with: fetch-depth: 0 submodules: 'true' + - uses: actions/checkout@v3 + name: Checkout Extension CI tools + if: ${{inputs.override_ci_tools_ref != ''}} + with: + path: 'extension-ci-tools' + ref: ${{ inputs.override_ci_tools_ref }} + repository: ${{ inputs.override_ci_tools_repository }} + fetch-depth: 0 + - name: Checkout DuckDB to version run: | cd duckdb @@ -358,6 +542,12 @@ jobs: with: version: 'latest' + - name: Setup Rust for cross compilation + if: ${{ (inputs.enable_rust || contains(format(';{0};', inputs.extra_toolchains), ';rust;'))}} + uses: dtolnay/rust-toolchain@stable + with: + targets: wasm32-unknown-emscripten + - name: Setup vcpkg uses: lukka/run-vcpkg@v11.1 with: @@ -378,4 +568,4 @@ jobs: if-no-files-found: error name: ${{ inputs.extension_name }}-${{ inputs.duckdb_version }}-extension-${{matrix.duckdb_arch}}${{inputs.artifact_postfix}} path: | - build/${{ matrix.duckdb_arch }}/extension/${{ inputs.extension_name }}/${{ inputs.extension_name }}.duckdb_extension.wasm + build/${{ matrix.duckdb_arch }}/extension/${{ inputs.extension_name }}/${{ inputs.extension_name }}.duckdb_extension.wasm \ No newline at end of file diff --git a/spatial/src/spatial/core/functions/scalar/st_asgeojson.cpp b/spatial/src/spatial/core/functions/scalar/st_asgeojson.cpp index 90a17047..c4479e30 100644 --- a/spatial/src/spatial/core/functions/scalar/st_asgeojson.cpp +++ b/spatial/src/spatial/core/functions/scalar/st_asgeojson.cpp @@ -238,10 +238,10 @@ static void GeometryToGeoJSONFragmentFunction(DataChunk &args, ExpressionState & Geometry::Match(geom, doc, obj); size_t json_size = 0; - // TODO: YYJSON_WRITE_PRETTY - auto json_data = yyjson_mut_write(doc, 0, &json_size); - auto json_str = StringVector::AddString(result, json_data, json_size); - return json_str; + char *json_data = yyjson_mut_write_opts(doc, 0, json_allocator.GetYYJSONAllocator(), &json_size, nullptr); + // Because the arena allocator only resets after each pipeline invocation, we can safely just point into the + // arena here without needing to copy the data to the string heap with StringVector::AddString + return string_t(json_data, json_size); }); } diff --git a/spatial/src/spatial/core/functions/scalar/st_extent.cpp b/spatial/src/spatial/core/functions/scalar/st_extent.cpp index 9a05d74e..0f06227c 100644 --- a/spatial/src/spatial/core/functions/scalar/st_extent.cpp +++ b/spatial/src/spatial/core/functions/scalar/st_extent.cpp @@ -7,7 +7,6 @@ #include "spatial/core/geometry/geometry.hpp" #include "spatial/core/types.hpp" - namespace spatial { namespace core { @@ -26,8 +25,9 @@ static uint32_t ReadInt(const bool le, Cursor &cursor) { } static void ReadWKB(Cursor &cursor, BoundingBox &bbox); -static void ReadWKB(const bool le, const uint32_t type, const bool has_z, const bool has_m, Cursor &cursor, BoundingBox &bbox) { - switch(type) { +static void ReadWKB(const bool le, const uint32_t type, const bool has_z, const bool has_m, Cursor &cursor, + BoundingBox &bbox) { + switch (type) { case 1: { // POINT // Points are special in that they can be all-nan (empty) bool all_nan = true; @@ -44,13 +44,13 @@ static void ReadWKB(const bool le, const uint32_t type, const bool has_z, const } break; case 2: { // LINESTRING const auto num_verts = ReadInt(le, cursor); - for(uint32_t i = 0; i < num_verts; i++) { + for (uint32_t i = 0; i < num_verts; i++) { const auto x = ReadDouble(le, cursor); const auto y = ReadDouble(le, cursor); - if(has_z) { + if (has_z) { ReadDouble(le, cursor); } - if(has_m) { + if (has_m) { ReadDouble(le, cursor); } bbox.Stretch(x, y); @@ -58,27 +58,27 @@ static void ReadWKB(const bool le, const uint32_t type, const bool has_z, const } break; case 3: { // POLYGON const auto num_rings = ReadInt(le, cursor); - for(uint32_t i = 0; i < num_rings; i++) { + for (uint32_t i = 0; i < num_rings; i++) { const auto num_verts = ReadInt(le, cursor); - for(uint32_t j = 0; j < num_verts; j++) { + for (uint32_t j = 0; j < num_verts; j++) { const auto x = ReadDouble(le, cursor); const auto y = ReadDouble(le, cursor); - if(has_z) { + if (has_z) { ReadDouble(le, cursor); } - if(has_m) { + if (has_m) { ReadDouble(le, cursor); } bbox.Stretch(x, y); } } } break; - case 4: // MULTIPOINT - case 5: // MULTILINESTRING - case 6: // MULTIPOLYGON + case 4: // MULTIPOINT + case 5: // MULTILINESTRING + case 6: // MULTIPOLYGON case 7: { // GEOMETRYCOLLECTION const auto num_items = ReadInt(le, cursor); - for(uint32_t i = 0; i < num_items; i++) { + for (uint32_t i = 0; i < num_items; i++) { ReadWKB(cursor, bbox); } } break; @@ -98,7 +98,7 @@ static void ReadWKB(Cursor &cursor, BoundingBox &bbox) { // Skip SRID if present const auto has_srid = (type & 0x20000000) != 0; - if(has_srid) { + if (has_srid) { cursor.Skip(sizeof(uint32_t)); } diff --git a/spatial/src/spatial/core/functions/scalar/st_geometrytype.cpp b/spatial/src/spatial/core/functions/scalar/st_geometrytype.cpp index a3055f7a..9b7c0b5c 100644 --- a/spatial/src/spatial/core/functions/scalar/st_geometrytype.cpp +++ b/spatial/src/spatial/core/functions/scalar/st_geometrytype.cpp @@ -55,9 +55,7 @@ static void GeometryTypeFunction(DataChunk &args, ExpressionState &state, Vector auto &input = args.data[0]; UnaryExecutor::Execute( - input, result, count, [&](const geometry_t &geom) { - return static_cast(geom.GetType()); - }); + input, result, count, [&](const geometry_t &geom) { return static_cast(geom.GetType()); }); } //------------------------------------------------------------------------------ @@ -72,7 +70,7 @@ static void WKBTypeFunction(DataChunk &args, ExpressionState &state, Vector &res const auto le = cursor.Read(); const auto type = le ? cursor.Read() : cursor.ReadBigEndian(); const auto normalized_type = (type & 0xffff) % 1000; - if(normalized_type == 0 || normalized_type > 7) { + if (normalized_type == 0 || normalized_type > 7) { throw InvalidInputException("WKB type '%d' is not a supported geometry type", type); } @@ -108,7 +106,7 @@ void CoreScalarFunctions::RegisterStGeometryType(DatabaseInstance &db) { ScalarFunction({GeoTypes::GEOMETRY()}, LogicalType::ANY, GeometryTypeFunction, GeometryTypeFunctionBind)); geometry_type_set.AddFunction( - ScalarFunction({GeoTypes::WKB_BLOB()}, LogicalType::ANY, WKBTypeFunction, GeometryTypeFunctionBind)); + ScalarFunction({GeoTypes::WKB_BLOB()}, LogicalType::ANY, WKBTypeFunction, GeometryTypeFunctionBind)); ExtensionUtil::RegisterFunction(db, geometry_type_set); DocUtil::AddDocumentation(db, "ST_GeometryType", DOC_DESCRIPTION, DOC_EXAMPLE, DOC_TAGS); diff --git a/spatial/src/spatial/core/functions/scalar/st_has.cpp b/spatial/src/spatial/core/functions/scalar/st_has.cpp index feacc9ee..c611d4f9 100644 --- a/spatial/src/spatial/core/functions/scalar/st_has.cpp +++ b/spatial/src/spatial/core/functions/scalar/st_has.cpp @@ -31,9 +31,15 @@ static void GeometryZMFlagFunction(DataChunk &args, ExpressionState &state, Vect const auto has_z = props.HasZ(); const auto has_m = props.HasM(); - if(has_z && has_m) { return 3; } - if(has_z) { return 2; } - if(has_m) { return 1; } + if (has_z && has_m) { + return 3; + } + if (has_z) { + return 2; + } + if (has_m) { + return 1; + } return 0; }); } @@ -68,9 +74,15 @@ static void WKBZMFlagFunction(DataChunk &args, ExpressionState &state, Vector &r const auto has_z = (iso_wkb_props == 1) || (iso_wkb_props == 3) || ((type & 0x80000000) != 0); const auto has_m = (iso_wkb_props == 2) || (iso_wkb_props == 3) || ((type & 0x40000000) != 0); - if(has_z && has_m) { return 3; } - if(has_z) { return 2; } - if(has_m) { return 1; } + if (has_z && has_m) { + return 3; + } + if (has_z) { + return 2; + } + if (has_m) { + return 1; + } return 0; }); } @@ -170,25 +182,16 @@ static constexpr const char *ZMFLAG_EXAMPLE = R"( //------------------------------------------------------------------------------ void CoreScalarFunctions::RegisterStHas(DatabaseInstance &db) { ScalarFunctionSet st_hasz("ST_HasZ"); - st_hasz.AddFunction(ScalarFunction({GeoTypes::GEOMETRY()}, LogicalType::BOOLEAN, - GeometryHasFunction)); - st_hasz.AddFunction(ScalarFunction({GeoTypes::WKB_BLOB()}, LogicalType::BOOLEAN, - WKBHasFunction)); - + st_hasz.AddFunction(ScalarFunction({GeoTypes::GEOMETRY()}, LogicalType::BOOLEAN, GeometryHasFunction)); + st_hasz.AddFunction(ScalarFunction({GeoTypes::WKB_BLOB()}, LogicalType::BOOLEAN, WKBHasFunction)); ScalarFunctionSet st_hasm("ST_HasM"); - st_hasm.AddFunction(ScalarFunction({GeoTypes::GEOMETRY()}, LogicalType::BOOLEAN, - GeometryHasFunction)); - st_hasm.AddFunction(ScalarFunction({GeoTypes::WKB_BLOB()}, LogicalType::BOOLEAN, - WKBHasFunction)); - + st_hasm.AddFunction(ScalarFunction({GeoTypes::GEOMETRY()}, LogicalType::BOOLEAN, GeometryHasFunction)); + st_hasm.AddFunction(ScalarFunction({GeoTypes::WKB_BLOB()}, LogicalType::BOOLEAN, WKBHasFunction)); ScalarFunctionSet st_zmflag("ST_ZMFlag"); - st_zmflag.AddFunction(ScalarFunction({GeoTypes::GEOMETRY()}, LogicalType::UTINYINT, - GeometryZMFlagFunction)); - st_zmflag.AddFunction(ScalarFunction({GeoTypes::WKB_BLOB()}, LogicalType::UTINYINT, - WKBZMFlagFunction)); - + st_zmflag.AddFunction(ScalarFunction({GeoTypes::GEOMETRY()}, LogicalType::UTINYINT, GeometryZMFlagFunction)); + st_zmflag.AddFunction(ScalarFunction({GeoTypes::WKB_BLOB()}, LogicalType::UTINYINT, WKBZMFlagFunction)); ExtensionUtil::RegisterFunction(db, st_hasz); ExtensionUtil::RegisterFunction(db, st_hasm); diff --git a/spatial/src/spatial/core/io/osm/st_read_osm.cpp b/spatial/src/spatial/core/io/osm/st_read_osm.cpp index 72b3b713..0a23a178 100644 --- a/spatial/src/spatial/core/io/osm/st_read_osm.cpp +++ b/spatial/src/spatial/core/io/osm/st_read_osm.cpp @@ -284,6 +284,20 @@ struct LocalState : LocalTableFunctionState { string_table.push_back(string_table_reader.get_string()); } + // Need to read ahead without advancing block_reader + auto reader_copy = block_reader; + + // Read the granularity and optional offsets + if (reader_copy.next(17)) { + granularity = reader_copy.get_int32(); + } + if (reader_copy.next(19)) { + lat_offset = reader_copy.get_int64(); + } + if (reader_copy.next(20)) { + lon_offset = reader_copy.get_int64(); + } + state = ParseState::Block; } @@ -310,17 +324,6 @@ struct LocalState : LocalTableFunctionState { case ParseState::Block: if (block_reader.next(2)) { group_reader = block_reader.get_message(); - - // Read the granularity and optional offsets - if (block_reader.next(17)) { - granularity = block_reader.get_int32(); - } - if (block_reader.next(19)) { - lat_offset = block_reader.get_int64(); - } - if (block_reader.next(20)) { - lon_offset = block_reader.get_int64(); - } state = ParseState::Group; } else { state = ParseState::End; diff --git a/spatial/src/spatial/core/io/shapefile/read_shapefile.cpp b/spatial/src/spatial/core/io/shapefile/read_shapefile.cpp index b799d1ef..9a15e4c1 100644 --- a/spatial/src/spatial/core/io/shapefile/read_shapefile.cpp +++ b/spatial/src/spatial/core/io/shapefile/read_shapefile.cpp @@ -37,8 +37,8 @@ struct ShapefileBindData : TableFunctionData { vector attribute_types; explicit ShapefileBindData(string file_name_p) - : file_name(std::move(file_name_p)), shape_count(0), shape_type(0), min_bound {0, 0, 0, 0}, - max_bound {0, 0, 0, 0}, attribute_encoding(AttributeEncoding::LATIN1) { + : file_name(std::move(file_name_p)), shape_count(0), + shape_type(0), min_bound {0, 0, 0, 0}, max_bound {0, 0, 0, 0}, attribute_encoding(AttributeEncoding::LATIN1) { } }; diff --git a/spatial/src/spatial/gdal/file_handler.cpp b/spatial/src/spatial/gdal/file_handler.cpp index cb50144d..3fe1abf5 100644 --- a/spatial/src/spatial/gdal/file_handler.cpp +++ b/spatial/src/spatial/gdal/file_handler.cpp @@ -385,10 +385,8 @@ string GDALClientContextState::GetPrefix(const string &value) const { } GDALClientContextState &GDALClientContextState::GetOrCreate(ClientContext &context) { - if (!context.registered_state["gdal"]) { - context.registered_state["gdal"] = make_uniq(context); - } - return *dynamic_cast(context.registered_state["gdal"].get()); + auto gdal_state = context.registered_state->GetOrCreate("gdal", context); + return *gdal_state; } } // namespace gdal