Skip to content

Commit

Permalink
[Fix](function) fix coredump of function StDistanceSphere and StAngle…
Browse files Browse the repository at this point in the history
…Sphere (#45508)

### What problem does this PR solve?

Issue Number: close #xxx

Related PR: #40107

Problem Summary:

In #40107 we introduced a wrong
behaviour which would lead to BE crash because of dangling reference.
now fix it.

### Release note

fix BE crash of function StDistanceSphere and StAngleSphere

### Check List (For Author)

- Test <!-- At least one of them must be included. -->
    - [x] Regression test
    - [ ] Unit Test
    - [ ] Manual test (add detailed scripts or steps below)
    - [ ] No need to test or manual test. Explain why:
- [ ] This is a refactor/code format and no logic has been changed.
        - [ ] Previous test can cover this change.
        - [ ] No code files have been changed.
        - [ ] Other reason <!-- Add your reason?  -->

- Behavior changed:
    - [x] No.
    - [ ] Yes. <!-- Explain the behavior change -->

- Does this need documentation?
    - [x] No.
- [ ] Yes. <!-- Add document PR link here. eg:
apache/doris-website#1214 -->

### Check List (For Reviewer who merge this PR)

- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label <!-- Add branch pick label that this PR
should merge into -->
  • Loading branch information
zclllyybb authored Dec 17, 2024
1 parent 57226bc commit 0603495
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 16 deletions.
43 changes: 27 additions & 16 deletions be/src/vec/functions/functions_geo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,21 @@ struct StDistanceSphere {
DCHECK_EQ(arguments.size(), 4);
auto return_type = block.get_data_type(result);

const auto* x_lng = check_and_get_column<ColumnFloat64>(
block.get_by_position(arguments[0]).column->convert_to_full_column_if_const());
const auto* x_lat = check_and_get_column<ColumnFloat64>(
block.get_by_position(arguments[1]).column->convert_to_full_column_if_const());
const auto* y_lng = check_and_get_column<ColumnFloat64>(
block.get_by_position(arguments[2]).column->convert_to_full_column_if_const());
const auto* y_lat = check_and_get_column<ColumnFloat64>(
block.get_by_position(arguments[3]).column->convert_to_full_column_if_const());
ColumnPtr x_lng_origin =
block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();
ColumnPtr x_lat_origin =
block.get_by_position(arguments[1]).column->convert_to_full_column_if_const();
ColumnPtr y_lng_origin =
block.get_by_position(arguments[2]).column->convert_to_full_column_if_const();
ColumnPtr y_lat_origin =
block.get_by_position(arguments[3]).column->convert_to_full_column_if_const();

const auto* x_lng = check_and_get_column<ColumnFloat64>(x_lng_origin);
const auto* x_lat = check_and_get_column<ColumnFloat64>(x_lat_origin);
const auto* y_lng = check_and_get_column<ColumnFloat64>(y_lng_origin);
const auto* y_lat = check_and_get_column<ColumnFloat64>(y_lat_origin);
CHECK(x_lng && x_lat && y_lng && y_lat);

const auto size = x_lng->size();
auto res = ColumnFloat64::create();
res->reserve(size);
Expand Down Expand Up @@ -290,14 +296,19 @@ struct StAngleSphere {
DCHECK_EQ(arguments.size(), 4);
auto return_type = block.get_data_type(result);

const auto* x_lng = check_and_get_column<ColumnFloat64>(
block.get_by_position(arguments[0]).column->convert_to_full_column_if_const());
const auto* x_lat = check_and_get_column<ColumnFloat64>(
block.get_by_position(arguments[1]).column->convert_to_full_column_if_const());
const auto* y_lng = check_and_get_column<ColumnFloat64>(
block.get_by_position(arguments[2]).column->convert_to_full_column_if_const());
const auto* y_lat = check_and_get_column<ColumnFloat64>(
block.get_by_position(arguments[3]).column->convert_to_full_column_if_const());
ColumnPtr x_lng_origin =
block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();
ColumnPtr x_lat_origin =
block.get_by_position(arguments[1]).column->convert_to_full_column_if_const();
ColumnPtr y_lng_origin =
block.get_by_position(arguments[2]).column->convert_to_full_column_if_const();
ColumnPtr y_lat_origin =
block.get_by_position(arguments[3]).column->convert_to_full_column_if_const();

const auto* x_lng = check_and_get_column<ColumnFloat64>(x_lng_origin);
const auto* x_lat = check_and_get_column<ColumnFloat64>(x_lat_origin);
const auto* y_lng = check_and_get_column<ColumnFloat64>(y_lng_origin);
const auto* y_lat = check_and_get_column<ColumnFloat64>(y_lat_origin);
CHECK(x_lng && x_lat && y_lng && y_lat);

const auto size = x_lng->size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,9 @@ LINESTRING (1 1, 2 2)
-- !sql --
POLYGON ((114.104486 22.547119, 114.093758 22.547753, 114.096504 22.532057, 114.104229 22.539826, 114.106203 22.54268, 114.104486 22.547119))

-- !sql_part_const_dis_sph --
3335.853035325018

-- !sql_part_const_ang_sph --
0.030000000000004495

Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,22 @@ suite("test_gis_function") {
qt_sql "SELECT ST_AsText(ST_GeomFromWKB(ST_AsBinary(ST_GeometryFromText(\"LINESTRING (1 1, 2 2)\"))));"
qt_sql "SELECT ST_AsText(ST_GeomFromWKB(ST_AsBinary(ST_Polygon(\"POLYGON ((114.104486 22.547119,114.093758 22.547753,114.096504 22.532057,114.104229 22.539826,114.106203 22.542680,114.104486 22.547119))\"))));"

// test const
sql "drop table if exists test_gis_const"
sql """
CREATE TABLE test_gis_const (
`userid` varchar(32) NOT NULL COMMENT '个人账号id',
`c_1` double NOT NULL COMMENT '发送时间',
`c_2` double NOT NULL COMMENT '信源类型'
) ENGINE=OLAP
UNIQUE KEY(`userid`)
COMMENT 'OLAP'
DISTRIBUTED BY HASH(`userid`) BUCKETS 6
PROPERTIES (
"replication_allocation" = "tag.location.default: 1"
);
"""
sql "insert into test_gis_const values ('xxxx',78.73,31.5);"
qt_sql_part_const_dis_sph "select st_distance_sphere(78.73,31.53,c_1,c_2) from test_gis_const; "
qt_sql_part_const_ang_sph "select st_angle_sphere(78.73,31.53,c_1,c_2) from test_gis_const; "
}

0 comments on commit 0603495

Please sign in to comment.