Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(query): ST_TRANSFORM #15992

Merged
merged 22 commits into from
Aug 9, 2024
Merged

Conversation

kkk25641463
Copy link
Contributor

@kkk25641463 kkk25641463 commented Jul 8, 2024

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

feat: Implement ST_TRANSFORM #15413

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - Explain why

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

This change is Reviewable

Signed-off-by: Fan Yang <yangfanlinux@gmail.com>
@kkk25641463 kkk25641463 marked this pull request as draft July 8, 2024 04:19
@github-actions github-actions bot added the pr-feature this PR introduces a new feature to the codebase label Jul 8, 2024
Signed-off-by: Fan Yang <yangfanlinux@gmail.com>
Signed-off-by: Fan Yang <yangfanlinux@gmail.com>

# Conflicts:
#	src/query/functions/src/scalars/geometry.rs
@kkk25641463
Copy link
Contributor Author

kkk25641463 commented Jul 8, 2024

  Install a sysroot for the target platform and configure it via
  PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_PATH, or install a
  cross-compiling wrapper for pkg-config and set it via
  PKG_CONFIG environment variable.
  building libproj from source
  disabling tiff support
  CMake Error at /usr/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:165 (message):
    Could NOT find SQLite3 (missing: SQLite3_LIBRARY) (found version "3.34.1")
  Call Stack (most recent call first):
    /usr/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:458 (_FPHSA_FAILURE_MESSAGE)
    /usr/share/cmake-3.18/Modules/FindSQLite3.cmake:52 (find_package_handle_standard_args)
    CMakeLists.txt:215 (find_package)
  thread 'main' panicked at /opt/rust/cargo/registry/src/index.crates.io-6f17d22bba15001f/cmake-0.1.50/src/lib.rs:1098:5:

@b41sh How could i check that cmake of build system can access libsqlite3 or fork the proj project and maintain it in databend project?

https://github.com/georust/proj/blob/46d46f287da00b1a3dccb5b3b34a0cd7eaff9622/proj-sys/build.rs#L122

@b41sh
Copy link
Member

b41sh commented Jul 8, 2024

  Install a sysroot for the target platform and configure it via
  PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_PATH, or install a
  cross-compiling wrapper for pkg-config and set it via
  PKG_CONFIG environment variable.
  building libproj from source
  disabling tiff support
  CMake Error at /usr/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:165 (message):
    Could NOT find SQLite3 (missing: SQLite3_LIBRARY) (found version "3.34.1")
  Call Stack (most recent call first):
    /usr/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:458 (_FPHSA_FAILURE_MESSAGE)
    /usr/share/cmake-3.18/Modules/FindSQLite3.cmake:52 (find_package_handle_standard_args)
    CMakeLists.txt:215 (find_package)
  thread 'main' panicked at /opt/rust/cargo/registry/src/index.crates.io-6f17d22bba15001f/cmake-0.1.50/src/lib.rs:1098:5:

@b41sh How could i check that cmake of build system can access libsqlite3 or fork the proj project and maintain it in databend project?

https://github.com/georust/proj/blob/46d46f287da00b1a3dccb5b3b34a0cd7eaff9622/proj-sys/build.rs#L122

Hi @kkk25641463 thanks for your contribution.
Adding sqlite is not easy, we recommended to submit the libsqlite3.a and related header files into the project code to compile directly, we have forked a proj project, you can make changes here.
https://github.com/datafuse-extras/proj

@b41sh b41sh self-requested a review July 8, 2024 09:39
Signed-off-by: Fan Yang <yangfanlinux@gmail.com>

# Conflicts:
#	src/query/functions/src/scalars/geometry.rs
@kkk25641463 kkk25641463 force-pushed the st_transform branch 2 times, most recently from 3ed3481 to cbf6172 Compare July 9, 2024 03:57
Signed-off-by: Fan Yang <yangfanlinux@gmail.com>

# Conflicts:
#	src/query/functions/src/scalars/geometry.rs
Signed-off-by: Fan Yang <yangfanlinux@gmail.com>

# Conflicts:
#	src/query/functions/src/scalars/geometry.rs
# Conflicts:
#	Cargo.lock
#	src/query/functions/Cargo.toml
Signed-off-by: Fan Yang <yangfanlinux@gmail.com>

# Conflicts:
#	Cargo.lock
#	src/query/functions/Cargo.toml
@kkk25641463 kkk25641463 force-pushed the st_transform branch 5 times, most recently from 4d0e532 to d781077 Compare July 10, 2024 09:40
Signed-off-by: Fan Yang <yangfanlinux@gmail.com>

# Conflicts:
#	Cargo.lock
@kkk25641463 kkk25641463 force-pushed the st_transform branch 3 times, most recently from b62dc33 to 2244da3 Compare July 10, 2024 10:31
@kkk25641463
Copy link
Contributor Author

@b41sh I want to get aarch64-unknown-linux-musl root path of gnu tools in docker images. Is there exist in image?

    let target = env::var("TARGET")?;
    let host = env::var("HOST")?;

    let mut configure_command = Command::new("./configure");
    configure_command.arg(format!("--prefix={}", &src_dir))
        .arg("--disable-tcl")
        .env("CFLAGS", "-D_LARGEFILE64_SOURCE")
        .current_dir(&src_dir)
        .stdout(Stdio::inherit())
        .stderr(Stdio::inherit());
    if target != host {
       // format target to root path.
        let cc = format!("{}-gcc", target);
        let cxx = format!("{}-g++", target);
        let ld = format!("{}-ld", target);
        let ar = format!("{}-ar", target);
        let as_ = format!("{}-as", target);
        let ranlib = format!("{}-ranlib", target);

        // println!("cargo:warning=Setting cross-compile tools for target: {}", target);
        configure_command
            .arg(format!("--host={}", target))
            .env("CC", cc)
            .env("CXX", cxx)
            .env("LD", ld)
            .env("AR", ar)
            .env("AS", as_)
            .env("RANLIB", ranlib);
    }

@kkk25641463 kkk25641463 force-pushed the st_transform branch 2 times, most recently from 0592783 to 4bca25e Compare July 10, 2024 14:38
@kkk25641463 kkk25641463 force-pushed the st_transform branch 2 times, most recently from 8d1e4bb to d7507a6 Compare July 11, 2024 09:44
@kkk25641463
Copy link
Contributor Author

@b41sh how do i check mysql unit test err.

Completed MySQL test for file: tests/sqllogictests/suites/query/window_function/window_basic.test ✅ (46.991542813s)
Test finished, fail fast enabled, 1 out of 5538 records failed to run
0: query failed: mysql client error: Server error: `ERROR HY000 (1105): BadArguments. Code: 1006, Text = error: 
  --> SQL:1:18
  |
1 | SELECT to_string(ST_TRANSFORM(g, 3857)) AS transformed_geom FROM t1
  |                  ^^^^^^^^^^^^^^^^^^^^^ GeometryError. Code: 1801, Text = The underlying PROJ call failed: Unknown error (code 2). while evaluating function `st_transform('SRID=32633;POINT(389866.35 5819003.03)', 3857)` in expr `st_transform(t1.g (#1), 3857)`
Error: SelfError("sqllogictest failed")

.'
[SQL] SELECT to_string(ST_TRANSFORM(g, 3857)) AS transformed_geom FROM t1
at tests/sqllogictests/suites/query/functions/02_0060_function_geometry.test:76

@b41sh
Copy link
Member

b41sh commented Jul 11, 2024

@b41sh how do i check mysql unit test err.

Completed MySQL test for file: tests/sqllogictests/suites/query/window_function/window_basic.test ✅ (46.991542813s)
Test finished, fail fast enabled, 1 out of 5538 records failed to run
0: query failed: mysql client error: Server error: `ERROR HY000 (1105): BadArguments. Code: 1006, Text = error: 
  --> SQL:1:18
  |
1 | SELECT to_string(ST_TRANSFORM(g, 3857)) AS transformed_geom FROM t1
  |                  ^^^^^^^^^^^^^^^^^^^^^ GeometryError. Code: 1801, Text = The underlying PROJ call failed: Unknown error (code 2). while evaluating function `st_transform('SRID=32633;POINT(389866.35 5819003.03)', 3857)` in expr `st_transform(t1.g (#1), 3857)`
Error: SelfError("sqllogictest failed")

.'
[SQL] SELECT to_string(ST_TRANSFORM(g, 3857)) AS transformed_geom FROM t1
at tests/sqllogictests/suites/query/functions/02_0060_function_geometry.test:76

@kkk25641463 I'm not sure, it looks like a proj execution error, but it's not reproducible in my local environment. I'll take a closer look at this later.

Signed-off-by: Fan Yang <yangfanlinux@gmail.com>
@b41sh
Copy link
Member

b41sh commented Jul 25, 2024

@kkk25641463 I found a proj library implemented by Rust proj4rs, which does not need to rely on sqlite3, and can implement lightweight CRS to CRS transform. We can consider using this library to implement st_transform function. I will continue to complete this work.

@b41sh b41sh marked this pull request as ready for review August 8, 2024 02:57
@b41sh
Copy link
Member

b41sh commented Aug 8, 2024

I have modified it in proj4rs. PTAL @sundy-li @kkk25641463

@b41sh b41sh requested a review from sundy-li August 8, 2024 02:59
@b41sh b41sh enabled auto-merge August 9, 2024 09:27
@b41sh b41sh added this pull request to the merge queue Aug 9, 2024
@BohuTANG BohuTANG removed this pull request from the merge queue due to a manual request Aug 9, 2024
@BohuTANG BohuTANG merged commit d24996b into databendlabs:main Aug 9, 2024
70 checks passed
@kkk25641463 kkk25641463 deleted the st_transform branch August 10, 2024 02:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-feature this PR introduces a new feature to the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants