Skip to content

Commit

Permalink
[branch-3.0](function) fix coredump of function StDistanceSphere and …
Browse files Browse the repository at this point in the history
…StAngleSphere (#45508) (#45526)

pick #45508
  • Loading branch information
zclllyybb authored Dec 25, 2024
1 parent 7e12a74 commit d52c555
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 d52c555

Please sign in to comment.