From b3843f9a1c4d91360587283c9cb73f4ab3cc3158 Mon Sep 17 00:00:00 2001 From: Ning Sun Date: Wed, 25 Sep 2024 20:18:04 -0700 Subject: [PATCH 1/7] feat: add more h3 grid functions --- src/common/function/src/scalars/geo.rs | 24 +- src/common/function/src/scalars/geo/h3.rs | 273 +++++++++++++++--- .../standalone/common/function/geo.result | 23 +- .../cases/standalone/common/function/geo.sql | 8 +- 4 files changed, 256 insertions(+), 72 deletions(-) diff --git a/src/common/function/src/scalars/geo.rs b/src/common/function/src/scalars/geo.rs index 8ad6a7aef22..d05cca0da2f 100644 --- a/src/common/function/src/scalars/geo.rs +++ b/src/common/function/src/scalars/geo.rs @@ -27,18 +27,28 @@ impl GeoFunctions { // geohash registry.register(Arc::new(GeohashFunction)); registry.register(Arc::new(GeohashNeighboursFunction)); - // h3 family + + // h3 index registry.register(Arc::new(h3::H3LatLngToCell)); registry.register(Arc::new(h3::H3LatLngToCellString)); + + // h3 index inspection registry.register(Arc::new(h3::H3CellBase)); - registry.register(Arc::new(h3::H3CellCenterChild)); + registry.register(Arc::new(h3::H3CellIsPentagon)); + registry.register(Arc::new(h3::H3StringToCell)); + registry.register(Arc::new(h3::H3CellToString)); registry.register(Arc::new(h3::H3CellCenterLat)); registry.register(Arc::new(h3::H3CellCenterLng)); - registry.register(Arc::new(h3::H3CellIsPentagon)); - registry.register(Arc::new(h3::H3CellParent)); registry.register(Arc::new(h3::H3CellResolution)); - registry.register(Arc::new(h3::H3CellToString)); - registry.register(Arc::new(h3::H3IsNeighbour)); - registry.register(Arc::new(h3::H3StringToCell)); + + // h3 hierarchical grid + registry.register(Arc::new(h3::H3CellCenterChild)); + registry.register(Arc::new(h3::H3CellParent)); + registry.register(Arc::new(h3::H3CellToChildren)); + registry.register(Arc::new(h3::H3CellToChildrenSize)); + registry.register(Arc::new(h3::H3CellToChildPos)); + registry.register(Arc::new(h3::H3ChildPosToCell)); + + // h3 grid traversal } } diff --git a/src/common/function/src/scalars/geo/h3.rs b/src/common/function/src/scalars/geo/h3.rs index 672fbfd7145..fa12a2beb18 100644 --- a/src/common/function/src/scalars/geo/h3.rs +++ b/src/common/function/src/scalars/geo/h3.rs @@ -20,11 +20,11 @@ use common_query::error::{self, InvalidFuncArgsSnafu, Result}; use common_query::prelude::{Signature, TypeSignature}; use datafusion::logical_expr::Volatility; use datatypes::prelude::ConcreteDataType; -use datatypes::scalars::ScalarVectorBuilder; -use datatypes::value::Value; +use datatypes::scalars::{Scalar, ScalarVectorBuilder}; +use datatypes::value::{ListValue, Value}; use datatypes::vectors::{ - BooleanVectorBuilder, Float64VectorBuilder, MutableVector, StringVectorBuilder, - UInt64VectorBuilder, UInt8VectorBuilder, VectorRef, + BooleanVectorBuilder, Float64VectorBuilder, ListVectorBuilder, MutableVector, + StringVectorBuilder, UInt64VectorBuilder, UInt8VectorBuilder, VectorRef, }; use derive_more::Display; use h3o::{CellIndex, LatLng, Resolution}; @@ -633,22 +633,24 @@ impl Function for H3CellParent { } } -/// Function that checks if two cells are neighbour +/// Function that returns children cell list #[derive(Clone, Debug, Default, Display)] #[display("{}", self.name())] -pub struct H3IsNeighbour; +pub struct H3CellToChildren; -impl Function for H3IsNeighbour { +impl Function for H3CellToChildren { fn name(&self) -> &str { - "h3_is_neighbour" + "h3_cell_to_children" } fn return_type(&self, _input_types: &[ConcreteDataType]) -> Result { - Ok(ConcreteDataType::boolean_datatype()) + Ok(ConcreteDataType::list_datatype( + ConcreteDataType::uint64_datatype(), + )) } fn signature(&self) -> Signature { - signature_of_double_cell() + signature_of_cell_and_resolution() } fn eval(&self, _func_ctx: FunctionContext, columns: &[VectorRef]) -> Result { @@ -663,30 +665,199 @@ impl Function for H3IsNeighbour { ); let cell_vec = &columns[0]; - let cell2_vec = &columns[1]; + let res_vec = &columns[1]; let size = cell_vec.len(); - let mut results = BooleanVectorBuilder::with_capacity(size); + let mut results = + ListVectorBuilder::with_type_capacity(ConcreteDataType::uint64_datatype(), size); for i in 0..size { - let result = match ( - cell_from_value(cell_vec.get(i))?, - cell_from_value(cell2_vec.get(i))?, - ) { - (Some(cell_this), Some(cell_that)) => { - let is_neighbour = cell_this - .is_neighbor_with(cell_that) - .map_err(|e| { - BoxedError::new(PlainError::new( - format!("H3 error: {}", e), - StatusCode::EngineExecuteQuery, - )) - }) - .context(error::ExecuteSnafu)?; - Some(is_neighbour) + let cell = cell_from_value(cell_vec.get(i))?; + let res = value_to_resolution(res_vec.get(i))?; + let result = cell.and_then(|cell| { + let children: Vec = cell + .children(res) + .map(|child| Value::from(u64::from(child))) + .collect(); + Some(ListValue::new( + children, + ConcreteDataType::uint64_datatype(), + )) + }); + + if let Some(list_value) = result { + results.push(Some(list_value.as_scalar_ref())); + } else { + results.push(None); + } + } + + Ok(results.to_vector()) + } +} + +/// Function that returns children cell count +#[derive(Clone, Debug, Default, Display)] +#[display("{}", self.name())] +pub struct H3CellToChildrenSize; + +impl Function for H3CellToChildrenSize { + fn name(&self) -> &str { + "h3_cell_to_children_size" + } + + fn return_type(&self, _input_types: &[ConcreteDataType]) -> Result { + Ok(ConcreteDataType::uint64_datatype()) + } + + fn signature(&self) -> Signature { + signature_of_cell_and_resolution() + } + + fn eval(&self, _func_ctx: FunctionContext, columns: &[VectorRef]) -> Result { + ensure!( + columns.len() == 2, + InvalidFuncArgsSnafu { + err_msg: format!( + "The length of the args is not correct, expect 2, provided : {}", + columns.len() + ), + } + ); + + let cell_vec = &columns[0]; + let res_vec = &columns[1]; + let size = cell_vec.len(); + let mut results = UInt64VectorBuilder::with_capacity(size); + + for i in 0..size { + let cell = cell_from_value(cell_vec.get(i))?; + let res = value_to_resolution(res_vec.get(i))?; + let result = cell.map(|cell| cell.children_count(res)); + results.push(result); + } + + Ok(results.to_vector()) + } +} + +/// Function that returns the cell position if its parent at given resolution +#[derive(Clone, Debug, Default, Display)] +#[display("{}", self.name())] +pub struct H3CellToChildPos; + +impl Function for H3CellToChildPos { + fn name(&self) -> &str { + "h3_cell_to_child_pos" + } + + fn return_type(&self, _input_types: &[ConcreteDataType]) -> Result { + Ok(ConcreteDataType::uint64_datatype()) + } + + fn signature(&self) -> Signature { + signature_of_cell_and_resolution() + } + + fn eval(&self, _func_ctx: FunctionContext, columns: &[VectorRef]) -> Result { + ensure!( + columns.len() == 2, + InvalidFuncArgsSnafu { + err_msg: format!( + "The length of the args is not correct, expect 2, provided : {}", + columns.len() + ), + } + ); + + let cell_vec = &columns[0]; + let res_vec = &columns[1]; + let size = cell_vec.len(); + let mut results = UInt64VectorBuilder::with_capacity(size); + + for i in 0..size { + let cell = cell_from_value(cell_vec.get(i))?; + let res = value_to_resolution(res_vec.get(i))?; + let result = cell.and_then(|cell| cell.child_position(res)); + results.push(result); + } + + Ok(results.to_vector()) + } +} + +/// Function that returns the cell at given position of the parent at given resolution +#[derive(Clone, Debug, Default, Display)] +#[display("{}", self.name())] +pub struct H3ChildPosToCell; + +impl Function for H3ChildPosToCell { + fn name(&self) -> &str { + "h3_child_pos_to_cell" + } + + fn return_type(&self, _input_types: &[ConcreteDataType]) -> Result { + Ok(ConcreteDataType::uint64_datatype()) + } + + fn signature(&self) -> Signature { + let mut signatures = Vec::new(); + for position_type in &[ + ConcreteDataType::int8_datatype(), + ConcreteDataType::int16_datatype(), + ConcreteDataType::int32_datatype(), + ConcreteDataType::int64_datatype(), + ConcreteDataType::uint8_datatype(), + ConcreteDataType::uint16_datatype(), + ConcreteDataType::uint32_datatype(), + ConcreteDataType::uint64_datatype(), + ] { + for cell_type in &[ + ConcreteDataType::uint64_datatype(), + ConcreteDataType::int64_datatype(), + ] { + for resolution_type in &[ + ConcreteDataType::int8_datatype(), + ConcreteDataType::int16_datatype(), + ConcreteDataType::int32_datatype(), + ConcreteDataType::int64_datatype(), + ConcreteDataType::uint8_datatype(), + ConcreteDataType::uint16_datatype(), + ConcreteDataType::uint32_datatype(), + ConcreteDataType::uint64_datatype(), + ] { + signatures.push(TypeSignature::Exact(vec![ + position_type.clone(), + cell_type.clone(), + resolution_type.clone(), + ])); } - _ => None, - }; + } + } + Signature::one_of(signatures, Volatility::Stable) + } + fn eval(&self, _func_ctx: FunctionContext, columns: &[VectorRef]) -> Result { + ensure!( + columns.len() == 3, + InvalidFuncArgsSnafu { + err_msg: format!( + "The length of the args is not correct, expect 3, provided : {}", + columns.len() + ), + } + ); + + let pos_vec = &columns[0]; + let cell_vec = &columns[1]; + let res_vec = &columns[2]; + let size = cell_vec.len(); + let mut results = UInt64VectorBuilder::with_capacity(size); + + for i in 0..size { + let cell = cell_from_value(cell_vec.get(i))?; + let pos = value_to_position(pos_vec.get(i))?; + let res = value_to_resolution(res_vec.get(i))?; + let result = cell.and_then(|cell| cell.child_at(pos, res).map(u64::from)); results.push(result); } @@ -716,6 +887,32 @@ fn value_to_resolution(v: Value) -> Result { .context(error::ExecuteSnafu) } +macro_rules! ensure_and_coerce { + ($compare:expr, $coerce:expr) => {{ + ensure!( + $compare, + InvalidFuncArgsSnafu { + err_msg: "Argument was outside of acceptable range " + } + ); + Ok($coerce) + }}; +} + +fn value_to_position(v: Value) -> Result { + match v { + Value::Int8(v) => ensure_and_coerce!(v > 0, v as u64), + Value::Int16(v) => ensure_and_coerce!(v > 0, v as u64), + Value::Int32(v) => ensure_and_coerce!(v > 0, v as u64), + Value::Int64(v) => ensure_and_coerce!(v > 0, v as u64), + Value::UInt8(v) => Ok(v as u64), + Value::UInt16(v) => Ok(v as u64), + Value::UInt32(v) => Ok(v as u64), + Value::UInt64(v) => Ok(v as u64), + _ => unreachable!(), + } +} + fn signature_of_cell() -> Signature { let mut signatures = Vec::new(); for cell_type in &[ @@ -728,24 +925,6 @@ fn signature_of_cell() -> Signature { Signature::one_of(signatures, Volatility::Stable) } -fn signature_of_double_cell() -> Signature { - let mut signatures = Vec::new(); - let cell_types = &[ - ConcreteDataType::uint64_datatype(), - ConcreteDataType::int64_datatype(), - ]; - for cell_type in cell_types { - for cell_type2 in cell_types { - signatures.push(TypeSignature::Exact(vec![ - cell_type.clone(), - cell_type2.clone(), - ])); - } - } - - Signature::one_of(signatures, Volatility::Stable) -} - fn signature_of_cell_and_resolution() -> Signature { let mut signatures = Vec::new(); for cell_type in &[ diff --git a/tests/cases/standalone/common/function/geo.result b/tests/cases/standalone/common/function/geo.result index 89544476503..6eddb10e10d 100644 --- a/tests/cases/standalone/common/function/geo.result +++ b/tests/cases/standalone/common/function/geo.result @@ -115,22 +115,17 @@ SELECT h3_cell_base(cell) AS base, h3_cell_is_pentagon(cell) AS pentagon, h3_cell_parent(cell, 6::UInt64) AS parent, + h3_cell_to_children(cell, 10::UInt64) AS children, + h3_cell_to_children_size(cell, 10) AS children_count, + h3_cell_to_child_pos(cell, 6) AS child_pos, + h3_child_pos_to_cell(25, cell, 11) AS child FROM (SELECT h3_latlng_to_cell(37.76938, -122.3889, 8::UInt64) AS cell); -+------------+------+----------+--------------------+ -| resolution | base | pentagon | parent | -+------------+------+----------+--------------------+ -| 8 | 20 | false | 604189371209351167 | -+------------+------+----------+--------------------+ - -SELECT h3_is_neighbour(cell1, cell2) -FROM (SELECT h3_latlng_to_cell(37.76938, -122.3889, 8::UInt64) AS cell1, h3_latlng_to_cell(36.76938, -122.3889, 8::UInt64) AS cell2); - -+------------------------------+ -| h3_is_neighbour(cell1,cell2) | -+------------------------------+ -| false | -+------------------------------+ ++------------+------+----------+--------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+-----------+--------------------+ +| resolution | base | pentagon | parent | children | children_count | child_pos | child | ++------------+------+----------+--------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+-----------+--------------------+ +| 8 | 20 | false | 604189371209351167 | [622203769691602943, 622203769691635711, 622203769691668479, 622203769691701247, 622203769691734015, 622203769691766783, 622203769691799551, 622203769691865087, 622203769691897855, 622203769691930623, 622203769691963391, 622203769691996159, 622203769692028927, 622203769692061695, 622203769692127231, 622203769692159999, 622203769692192767, 622203769692225535, 622203769692258303, 622203769692291071, 622203769692323839, 622203769692389375, 622203769692422143, 622203769692454911, 622203769692487679, 622203769692520447, 622203769692553215, 622203769692585983, 622203769692651519, 622203769692684287, 622203769692717055, 622203769692749823, 622203769692782591, 622203769692815359, 622203769692848127, 622203769692913663, 622203769692946431, 622203769692979199, 622203769693011967, 622203769693044735, 622203769693077503, 622203769693110271, 622203769693175807, 622203769693208575, 622203769693241343, 622203769693274111, 622203769693306879, 622203769693339647, 622203769693372415] | 49 | 45 | 626707369319059455 | ++------------+------+----------+--------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+-----------+--------------------+ SELECT geohash(37.76938, -122.3889, 9); diff --git a/tests/cases/standalone/common/function/geo.sql b/tests/cases/standalone/common/function/geo.sql index be2b3947bbc..3ce1863c863 100644 --- a/tests/cases/standalone/common/function/geo.sql +++ b/tests/cases/standalone/common/function/geo.sql @@ -33,12 +33,12 @@ SELECT h3_cell_base(cell) AS base, h3_cell_is_pentagon(cell) AS pentagon, h3_cell_parent(cell, 6::UInt64) AS parent, + h3_cell_to_children(cell, 10::UInt64) AS children, + h3_cell_to_children_size(cell, 10) AS children_count, + h3_cell_to_child_pos(cell, 6) AS child_pos, + h3_child_pos_to_cell(25, cell, 11) AS child FROM (SELECT h3_latlng_to_cell(37.76938, -122.3889, 8::UInt64) AS cell); -SELECT h3_is_neighbour(cell1, cell2) -FROM (SELECT h3_latlng_to_cell(37.76938, -122.3889, 8::UInt64) AS cell1, h3_latlng_to_cell(36.76938, -122.3889, 8::UInt64) AS cell2); - - SELECT geohash(37.76938, -122.3889, 9); SELECT geohash(37.76938, -122.3889, 10); From e84a73bc47337677c7806fe6714d134d99dda236 Mon Sep 17 00:00:00 2001 From: Ning Sun Date: Wed, 25 Sep 2024 21:51:46 -0700 Subject: [PATCH 2/7] feat: add more traversal functions --- src/common/function/src/scalars/geo.rs | 4 + src/common/function/src/scalars/geo/h3.rs | 340 +++++++++++++++++- .../standalone/common/function/geo.result | 28 ++ .../cases/standalone/common/function/geo.sql | 16 + 4 files changed, 382 insertions(+), 6 deletions(-) diff --git a/src/common/function/src/scalars/geo.rs b/src/common/function/src/scalars/geo.rs index d05cca0da2f..e41e934efbf 100644 --- a/src/common/function/src/scalars/geo.rs +++ b/src/common/function/src/scalars/geo.rs @@ -50,5 +50,9 @@ impl GeoFunctions { registry.register(Arc::new(h3::H3ChildPosToCell)); // h3 grid traversal + registry.register(Arc::new(h3::H3GridDisk)); + registry.register(Arc::new(h3::H3GridDiskDistances)); + registry.register(Arc::new(h3::H3GridDistance)); + registry.register(Arc::new(h3::H3GridPathCells)); } } diff --git a/src/common/function/src/scalars/geo/h3.rs b/src/common/function/src/scalars/geo/h3.rs index fa12a2beb18..26b21cc297c 100644 --- a/src/common/function/src/scalars/geo/h3.rs +++ b/src/common/function/src/scalars/geo/h3.rs @@ -23,8 +23,8 @@ use datatypes::prelude::ConcreteDataType; use datatypes::scalars::{Scalar, ScalarVectorBuilder}; use datatypes::value::{ListValue, Value}; use datatypes::vectors::{ - BooleanVectorBuilder, Float64VectorBuilder, ListVectorBuilder, MutableVector, - StringVectorBuilder, UInt64VectorBuilder, UInt8VectorBuilder, VectorRef, + BooleanVectorBuilder, Float64VectorBuilder, Int32VectorBuilder, ListVectorBuilder, + MutableVector, StringVectorBuilder, UInt64VectorBuilder, UInt8VectorBuilder, VectorRef, }; use derive_more::Display; use h3o::{CellIndex, LatLng, Resolution}; @@ -865,6 +865,277 @@ impl Function for H3ChildPosToCell { } } +/// Function that returns cells with k distances of given cell +#[derive(Clone, Debug, Default, Display)] +#[display("{}", self.name())] +pub struct H3GridDisk; + +impl Function for H3GridDisk { + fn name(&self) -> &str { + "h3_grid_disk" + } + + fn return_type(&self, _input_types: &[ConcreteDataType]) -> Result { + Ok(ConcreteDataType::list_datatype( + ConcreteDataType::uint64_datatype(), + )) + } + + fn signature(&self) -> Signature { + signature_of_cell_and_distance() + } + + fn eval(&self, _func_ctx: FunctionContext, columns: &[VectorRef]) -> Result { + ensure!( + columns.len() == 2, + InvalidFuncArgsSnafu { + err_msg: format!( + "The length of the args is not correct, expect 2, provided : {}", + columns.len() + ), + } + ); + + let cell_vec = &columns[0]; + let k_vec = &columns[1]; + let size = cell_vec.len(); + let mut results = + ListVectorBuilder::with_type_capacity(ConcreteDataType::uint64_datatype(), size); + + for i in 0..size { + let cell = cell_from_value(cell_vec.get(i))?; + let k = value_to_distance(k_vec.get(i))?; + + let result = cell.and_then(|cell| { + let children: Vec = cell + .grid_disk::>(k) + .into_iter() + .map(|child| Value::from(u64::from(child))) + .collect(); + Some(ListValue::new( + children, + ConcreteDataType::uint64_datatype(), + )) + }); + + if let Some(list_value) = result { + results.push(Some(list_value.as_scalar_ref())); + } else { + results.push(None); + } + } + + Ok(results.to_vector()) + } +} + +/// Function that returns all cells within k distances of given cell +#[derive(Clone, Debug, Default, Display)] +#[display("{}", self.name())] +pub struct H3GridDiskDistances; + +impl Function for H3GridDiskDistances { + fn name(&self) -> &str { + "h3_grid_disk_distances" + } + + fn return_type(&self, _input_types: &[ConcreteDataType]) -> Result { + Ok(ConcreteDataType::list_datatype( + ConcreteDataType::uint64_datatype(), + )) + } + + fn signature(&self) -> Signature { + signature_of_cell_and_distance() + } + + fn eval(&self, _func_ctx: FunctionContext, columns: &[VectorRef]) -> Result { + ensure!( + columns.len() == 2, + InvalidFuncArgsSnafu { + err_msg: format!( + "The length of the args is not correct, expect 2, provided : {}", + columns.len() + ), + } + ); + + let cell_vec = &columns[0]; + let k_vec = &columns[1]; + let size = cell_vec.len(); + let mut results = + ListVectorBuilder::with_type_capacity(ConcreteDataType::uint64_datatype(), size); + + for i in 0..size { + let cell = cell_from_value(cell_vec.get(i))?; + let k = value_to_distance(k_vec.get(i))?; + + let result = cell.and_then(|cell| { + let children: Vec = cell + .grid_disk_distances::>(k) + .into_iter() + .map(|(child, _distance)| Value::from(u64::from(child))) + .collect(); + Some(ListValue::new( + children, + ConcreteDataType::uint64_datatype(), + )) + }); + + if let Some(list_value) = result { + results.push(Some(list_value.as_scalar_ref())); + } else { + results.push(None); + } + } + + Ok(results.to_vector()) + } +} + +/// Function that returns distance between two cells +#[derive(Clone, Debug, Default, Display)] +#[display("{}", self.name())] +pub struct H3GridDistance; + +impl Function for H3GridDistance { + fn name(&self) -> &str { + "h3_grid_distance" + } + fn return_type(&self, _input_types: &[ConcreteDataType]) -> Result { + Ok(ConcreteDataType::int32_datatype()) + } + + fn signature(&self) -> Signature { + signature_of_double_cells() + } + + fn eval(&self, _func_ctx: FunctionContext, columns: &[VectorRef]) -> Result { + ensure!( + columns.len() == 2, + InvalidFuncArgsSnafu { + err_msg: format!( + "The length of the args is not correct, expect 2, provided : {}", + columns.len() + ), + } + ); + + let cell_this_vec = &columns[0]; + let cell_that_vec = &columns[1]; + let size = cell_this_vec.len(); + + let mut results = Int32VectorBuilder::with_capacity(size); + + for i in 0..size { + let result = match ( + cell_from_value(cell_this_vec.get(i))?, + cell_from_value(cell_that_vec.get(i))?, + ) { + (Some(cell_this), Some(cell_that)) => { + let dist = cell_this + .grid_distance(cell_that) + .map_err(|e| { + BoxedError::new(PlainError::new( + format!("H3 error: {}", e), + StatusCode::EngineExecuteQuery, + )) + }) + .context(error::ExecuteSnafu)?; + Some(dist) + } + _ => None, + }; + + results.push(result); + } + + Ok(results.to_vector()) + } +} + +/// Function that returns path cells between two cells +#[derive(Clone, Debug, Default, Display)] +#[display("{}", self.name())] +pub struct H3GridPathCells; + +impl Function for H3GridPathCells { + fn name(&self) -> &str { + "h3_grid_path_cells" + } + + fn return_type(&self, _input_types: &[ConcreteDataType]) -> Result { + Ok(ConcreteDataType::list_datatype( + ConcreteDataType::uint64_datatype(), + )) + } + + fn signature(&self) -> Signature { + signature_of_double_cells() + } + + fn eval(&self, _func_ctx: FunctionContext, columns: &[VectorRef]) -> Result { + ensure!( + columns.len() == 2, + InvalidFuncArgsSnafu { + err_msg: format!( + "The length of the args is not correct, expect 2, provided : {}", + columns.len() + ), + } + ); + + let cell_this_vec = &columns[0]; + let cell_that_vec = &columns[1]; + let size = cell_this_vec.len(); + let mut results = + ListVectorBuilder::with_type_capacity(ConcreteDataType::uint64_datatype(), size); + + for i in 0..size { + let result = match ( + cell_from_value(cell_this_vec.get(i))?, + cell_from_value(cell_that_vec.get(i))?, + ) { + (Some(cell_this), Some(cell_that)) => { + let cells = cell_this + .grid_path_cells(cell_that) + .map_err(|e| { + BoxedError::new(PlainError::new( + format!("H3 error: {}", e), + StatusCode::EngineExecuteQuery, + )) + }) + .context(error::ExecuteSnafu)? + .collect::, _>>() + .map_err(|e| { + BoxedError::new(PlainError::new( + format!("H3 error: {}", e), + StatusCode::EngineExecuteQuery, + )) + }) + .context(error::ExecuteSnafu)?; + Some(ListValue::new( + cells + .into_iter() + .map(|c| Value::from(u64::from(c))) + .collect(), + ConcreteDataType::uint64_datatype(), + )) + } + _ => None, + }; + + if let Some(list_value) = result { + results.push(Some(list_value.as_scalar_ref())); + } else { + results.push(None); + } + } + + Ok(results.to_vector()) + } +} + fn value_to_resolution(v: Value) -> Result { let r = match v { Value::Int8(v) => v as u8, @@ -901,10 +1172,10 @@ macro_rules! ensure_and_coerce { fn value_to_position(v: Value) -> Result { match v { - Value::Int8(v) => ensure_and_coerce!(v > 0, v as u64), - Value::Int16(v) => ensure_and_coerce!(v > 0, v as u64), - Value::Int32(v) => ensure_and_coerce!(v > 0, v as u64), - Value::Int64(v) => ensure_and_coerce!(v > 0, v as u64), + Value::Int8(v) => ensure_and_coerce!(v >= 0, v as u64), + Value::Int16(v) => ensure_and_coerce!(v >= 0, v as u64), + Value::Int32(v) => ensure_and_coerce!(v >= 0, v as u64), + Value::Int64(v) => ensure_and_coerce!(v >= 0, v as u64), Value::UInt8(v) => Ok(v as u64), Value::UInt16(v) => Ok(v as u64), Value::UInt32(v) => Ok(v as u64), @@ -913,6 +1184,20 @@ fn value_to_position(v: Value) -> Result { } } +fn value_to_distance(v: Value) -> Result { + match v { + Value::Int8(v) => ensure_and_coerce!(v >= 0, v as u32), + Value::Int16(v) => ensure_and_coerce!(v >= 0, v as u32), + Value::Int32(v) => ensure_and_coerce!(v >= 0, v as u32), + Value::Int64(v) => ensure_and_coerce!(v >= 0, v as u32), + Value::UInt8(v) => Ok(v as u32), + Value::UInt16(v) => Ok(v as u32), + Value::UInt32(v) => Ok(v as u32), + Value::UInt64(v) => Ok(v as u32), + _ => unreachable!(), + } +} + fn signature_of_cell() -> Signature { let mut signatures = Vec::new(); for cell_type in &[ @@ -925,6 +1210,24 @@ fn signature_of_cell() -> Signature { Signature::one_of(signatures, Volatility::Stable) } +fn signature_of_double_cells() -> Signature { + let mut signatures = Vec::new(); + let cell_types = &[ + ConcreteDataType::uint64_datatype(), + ConcreteDataType::int64_datatype(), + ]; + for cell_type in cell_types { + for cell_type2 in cell_types { + signatures.push(TypeSignature::Exact(vec![ + cell_type.clone(), + cell_type2.clone(), + ])); + } + } + + Signature::one_of(signatures, Volatility::Stable) +} + fn signature_of_cell_and_resolution() -> Signature { let mut signatures = Vec::new(); for cell_type in &[ @@ -950,6 +1253,31 @@ fn signature_of_cell_and_resolution() -> Signature { Signature::one_of(signatures, Volatility::Stable) } +fn signature_of_cell_and_distance() -> Signature { + let mut signatures = Vec::new(); + for cell_type in &[ + ConcreteDataType::uint64_datatype(), + ConcreteDataType::int64_datatype(), + ] { + for resolution_type in &[ + ConcreteDataType::int8_datatype(), + ConcreteDataType::int16_datatype(), + ConcreteDataType::int32_datatype(), + ConcreteDataType::int64_datatype(), + ConcreteDataType::uint8_datatype(), + ConcreteDataType::uint16_datatype(), + ConcreteDataType::uint32_datatype(), + ConcreteDataType::uint64_datatype(), + ] { + signatures.push(TypeSignature::Exact(vec![ + cell_type.clone(), + resolution_type.clone(), + ])); + } + } + Signature::one_of(signatures, Volatility::Stable) +} + fn cell_from_value(v: Value) -> Result> { let cell = match v { Value::Int64(v) => Some( diff --git a/tests/cases/standalone/common/function/geo.result b/tests/cases/standalone/common/function/geo.result index 6eddb10e10d..21caf3c8994 100644 --- a/tests/cases/standalone/common/function/geo.result +++ b/tests/cases/standalone/common/function/geo.result @@ -127,6 +127,34 @@ FROM (SELECT h3_latlng_to_cell(37.76938, -122.3889, 8::UInt64) AS cell); | 8 | 20 | false | 604189371209351167 | [622203769691602943, 622203769691635711, 622203769691668479, 622203769691701247, 622203769691734015, 622203769691766783, 622203769691799551, 622203769691865087, 622203769691897855, 622203769691930623, 622203769691963391, 622203769691996159, 622203769692028927, 622203769692061695, 622203769692127231, 622203769692159999, 622203769692192767, 622203769692225535, 622203769692258303, 622203769692291071, 622203769692323839, 622203769692389375, 622203769692422143, 622203769692454911, 622203769692487679, 622203769692520447, 622203769692553215, 622203769692585983, 622203769692651519, 622203769692684287, 622203769692717055, 622203769692749823, 622203769692782591, 622203769692815359, 622203769692848127, 622203769692913663, 622203769692946431, 622203769692979199, 622203769693011967, 622203769693044735, 622203769693077503, 622203769693110271, 622203769693175807, 622203769693208575, 622203769693241343, 622203769693274111, 622203769693306879, 622203769693339647, 622203769693372415] | 49 | 45 | 626707369319059455 | +------------+------+----------+--------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+-----------+--------------------+ +SELECT + h3_grid_disk(cell, 0) AS current_cell, + h3_grid_disk(cell, 3) AS grids, + h3_grid_disk_distances(cell, 3) AS all_grids, +FROM (SELECT h3_latlng_to_cell(37.76938, -122.3889, 8::UInt64) AS cell); + ++----------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| current_cell | grids | all_grids | ++----------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| [613196570438926335] | [613196570438926335, 613196570436829183, 613196569755254783, 613196570378108927, 613196570373914623, 613196570434732031, 613196570432634879, 613196570445217791, 613196570250182655, 613196569753157631, 613196569744769023, 613196569746866175, 613196570369720319, 613196570365526015, 613196570376011775, 613196570336165887, 613196570344554495, 613196570443120639, 613196570441023487, 613196570220822527, 613196570258571263, 613196570248085503, 613196570254376959, 613196569757351935, 613196569748963327, 613196569751060479, 613196569686048767, 613196569688145919, 613196570371817471, 613196570367623167, 613196570394886143, 613196570338263039, 613196570331971583, 613196570340360191, 613196570405371903, 613196570403274751, 613196570216628223] | [613196570438926335, 613196570436829183, 613196569755254783, 613196570378108927, 613196570373914623, 613196570434732031, 613196570432634879, 613196570445217791, 613196570250182655, 613196569753157631, 613196569744769023, 613196569746866175, 613196570369720319, 613196570365526015, 613196570376011775, 613196570336165887, 613196570344554495, 613196570443120639, 613196570441023487, 613196570220822527, 613196570258571263, 613196570248085503, 613196570254376959, 613196569757351935, 613196569748963327, 613196569751060479, 613196569686048767, 613196569688145919, 613196570371817471, 613196570367623167, 613196570394886143, 613196570338263039, 613196570331971583, 613196570340360191, 613196570405371903, 613196570403274751, 613196570216628223] | ++----------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ + +SELECT + h3_grid_distance(cell1, cell2) AS distance, + h3_grid_path_cells(cell1, cell2) AS path_cells, +FROM + ( + SELECT + h3_latlng_to_cell(37.76938, -122.3889, 8::UInt64) AS cell1, + h3_latlng_to_cell(39.634, -104.999, 8::UInt64) AS cell2 + ); + ++----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| distance | path_cells | ++----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| 1612 | [613196570438926335, 613196569755254783, 613196569744769023, 613196569748963327, 613196569669271551, 613196569673465855, 613196569763643391, 613196569767837695, 613196570023690239, 613196570021593087, 613196570025787391, 613196569998524415, 613196570002718719, 613196570040467455, 613196570029981695, 613196570034175999, 613196572437512191, 613196572441706495, 613196572414443519, 613196572418637823, 613196572456386559, 613196572445900799, 613196572450095103, 613196572705947647, 613196572710141951, 613196572691267583, 613196572680781823, 613196572684976127, 613196572722724863, 613196572726919167, 613196592932978687, 613196592937172991, 613196592421273599, 613196592410787839, 613196592414982143, 613196592452730879, 613196592456925183, 613196592261890047, 613196592266084351, 613196592689709055, 613196592679223295, 613196592683417599, 613196592496771071, 613196592500965375, 613196592538714111, 613196592528228351, 613196592532422655, 613196587587338239, 613196587591532543, 613196587396497407, 613196587400691711, 613196587438440447, 613196587427954687, 613196587432148991, 613196586916249599, 613196586920443903, 613196587664932863, 613196587669127167, 613196587706875903, 613196587704778751, 613196587708973055, 613196587681710079, 613196587685904383, 613196593444683775, 613196593434198015, 613196593438392319, 613196593476141055, 613196593480335359, 613196593453072383, 613196593457266687, 613196593713119231, 613196593702633471, 613196593706827775, 613196593744576511, 613196593748770815, 613196593729896447, 613196593719410687, 613196593723604991, 613196962272903167, 613196962277097471, 613196962249834495, 613196962254028799, 613196962291777535, 613196962281291775, 613196962285486079, 613196961601814527, 613196961606008831, 613196961578745855, 613196961582940159, 613196961620688895, 613196961610203135, 613196961614397439, 613196961931067391, 613196961935261695, 613196961855569919, 613196961845084159, 613196961849278463, 613196961887027199, 613196961891221503, 613196956830793727, 613196956834988031, 613196956755296255, 613196956744810495, 613196956749004799, 613196956786753535, 613196956790947839, 613196957099229183, 613196957103423487, 613196957023731711, 613196957021634559, 613196957025828863, 613196957116006399, 613196957120200703, 613196962878980095, 613196962868494335, 613196962872688639, 613196962792996863, 613196962797191167, 613196962887368703, 613196962891563007, 613196963147415551, 613196963136929791, 613196963141124095, 613196963061432319, 613196963065626623, 613196963164192767, 613196963153707007, 613196963157901311, 613196979519881215, 613196979524075519, 613196979496812543, 613196979501006847, 613196979538755583, 613196979528269823, 613196979532464127, 613196978848792575, 613196978852986879, 613196978825723903, 613196978829918207, 613196978867666943, 613196978857181183, 613196978861375487, 613196979614253055, 613196979618447359, 613196979102547967, 613196979092062207, 613196979096256511, 613196979134005247, 613196979138199551, 613196977869422591, 613196977873616895, 613196974002274303, 613196973991788543, 613196973995982847, 613196974033731583, 613196974037925887, 613196978137858047, 613196978142052351, 613196978139955199, 613196974268612607, 613196974272806911, 613196980520222719, 613196980524417023, 613196980562165759, 613196980551679999, 613196980555874303, 613196980039974911, 613196980044169215, 613196979849134079, 613196979853328383, 613196979891077119, 613196979880591359, 613196979884785663, 613196980308410367, 613196980312604671, 613196980125958143, 613196980115472383, 613196980119666687, 613196980157415423, 613196980161609727, 613196980134346751, 613196980138541055, 613220567281041407, 613220567270555647, 613220567274749951, 613220567312498687, 613220567316692991, 613220567289430015, 613220567293624319, 613220567549476863, 613220567538991103, 613220567543185407, 613220567524311039, 613220567528505343, 613220567566254079, 613220567555768319, 613220567559962623, 613220565802549247, 613220565806743551, 613220565779480575, 613220565783674879, 613220565821423615, 613220565810937855, 613220565815132159, 613220566070984703, 613220566075179007, 613220566047916031, 613220566052110335, 613220566050013183, 613220566087761919, 613220566091956223, 613220568547721215, 613220568551915519, 613220568472223743, 613220568461737983, 613220568465932287, 613220568503681023, 613220568507875327, 613220567876632575, 613220567880826879, 613220567801135103, 613220567790649343, 613220567794843647, 613220567832592383, 613220567836786687, 613220568153456639, 613220568142970879, 613220568147165183, 613220568067473407, 613220568071667711, 613220568161845247, 613220568166039551, 613220524398477311, 613220524387991551, 613220524392185855, 613220524312494079, 613220524316688383, 613220524406865919, 613220524411060223, 613220524666912767, 613220524656427007, 613220524669009919, 613220524641746943, 613220524645941247, 613220524683689983, 613220524673204223, 613220524677398527, 613220522919985151, 613220522924179455, 613220522896916479, 613220522901110783, 613220522938859519, 613220522928373759, 613220522932568063, 613220523188420607, 613220523192614911, 613220523165351935, 613220523169546239, 613220523167449087, 613220523205197823, 613220523209392127, 613220523014356991, 613220523018551295, 613220525589659647, 613220525579173887, 613220525583368191, 613220525621116927, 613220525625311231, 613220525430276095, 613220525434470399, 613220524918571007, 613220524908085247, 613220524912279551, 613220524950028287, 613220524954222591, 613220525707100159, 613220525696614399, 613220525700808703, 613220525184909311, 613220525189103615, 613220573312450559, 613220573316644863, 613220573354393599, 613220573343907839, 613220573348102143, 613220541559472127, 613220541563666431, 613220573580886015, 613220573585080319, 613220573622829055, 613220573612343295, 613220573624926207, 613220573597663231, 613220573601857535, 613220540571713535, 613220540561227775, 613220540565422079, 613220540603170815, 613220540607365119, 613220540580102143, 613220540584296447, 613220539900624895, 613220539890139135, 613220539894333439, 613220539932082175, 613220539936276479, 613220539909013503, 613220539913207807, 613220539911110655, 613220540166963199, 613220540171157503, 613220540143894527, 613220540148088831, 613220540185837567, 613220540175351807, 613220540179546111, 613220542582882303, 613220542587076607, 613220542559813631, 613220542564007935, 613220542601756671, 613220542591270911, 613220542595465215, 613220542851317759, 613220542855512063, 613220542836637695, 613220542826151935, 613220542830346239, 613220542868094975, 613220542872289279, 613220461710409727, 613220461714604031, 613220461634912255, 613220461624426495, 613220461628620799, 613220461666369535, 613220461670563839, 613220461978845183, 613220461983039487, 613220461903347711, 613220461892861951, 613220461905444863, 613220461995622399, 613220461999816703, 613220214221307903, 613220214210822143, 613220214215016447, 613220214135324671, 613220214139518975, 613220214229696511, 613220214233890815, 613220213550219263, 613220213539733503, 613220213543927807, 613220213464236031, 613220213468430335, 613220213558607871, 613220213562802175, 613220213560705023, 613220213816557567, 613220213820751871, 613220213793488895, 613220213797683199, 613220213835431935, 613220213824946175, 613220213829140479, 613220216232476671, 613220216236670975, 613220216209407999, 613220216213602303, 613220216251351039, 613220216240865279, 613220216245059583, 613220216500912127, 613220476981870591, 613220216486232063, 613220216475746303, 613220216479940607, 613220216517689343, 613220216521883647, 613220479393595391, 613220479397789695, 613220478881890303, 613220478871404543, 613220478875598847, 613220478913347583, 613220478917541887, 613220478722506751, 613220478726701055, 613220479150325759, 613220479139839999, 613220479152422911, 613220478957387775, 613220478961582079, 613220478999330815, 613220478988845055, 613220478993039359, 613220231382302719, 613220231386497023, 613220231191461887, 613220231195656191, 613220231233404927, 613220231222919167, 613220231227113471, 613220230711214079, 613220230715408383, 613220231459897343, 613220231464091647, 613220231461994495, 613220231499743231, 613220231503937535, 613220231476674559, 613220231480868863, 613220631302897663, 613220631292411903, 613220631296606207, 613220631334354943, 613220631338549247, 613220631311286271, 613220631315480575, 613220631571333119, 613220631560847359, 613220631565041663, 613220631602790399, 613220631550361599, 613220631588110335, 613220631577624575, 613220631581818879, 613220633985155071, 613220633989349375, 613220633962086399, 613220633966280703, 613220634004029439, 613220633993543679, 613220633997737983, 613220633314066431, 613220633318260735, 613220633290997759, 613220633295192063, 613220633332940799, 613220633322455039, 613220633335037951, 613220633643319295, 613220633647513599, 613220633567821823, 613220633557336063, 613220633561530367, 613220633599279103, 613220633603473407, 613220600625758207, 613220600629952511, 613220600550260735, 613220600539774975, 613220600543969279, 613220600581718015, 613220600585912319, 613220600894193663, 613220600898387967, 613220600896290815, 613220600816599039, 613220600820793343, 613220600910970879, 613220600915165183, 613220588420333567, 613220588409847807, 613220588414042111, 613220588334350335, 613220588338544639, 613220588428722175, 613220588432916479, 613220588688769023, 613220588678283263, 613220588682477567, 613220588602785791, 613220588667797503, 613220588705546239, 613220588695060479, 613220588699254783, 613220591102590975, 613220591106785279, 613220591079522303, 613220591083716607, 613220591121465343, 613220591110979583, 613220591115173887, 613220590431502335, 613220590435696639, 613220590408433663, 613220590412627967, 613220590450376703, 613220590439890943, 613220590452473855, 613220591196962815, 613220591201157119, 613220590685257727, 613220590674771967, 613220590678966271, 613220590716715007, 613220590720909311, 613220589452132351, 613220589456326655, 613220617797238783, 613220617786753023, 613220617790947327, 613220617828696063, 613220617832890367, 613220589720567807, 613220589718470655, 613220589722664959, 613220618063577087, 613220618067771391, 613220606061576191, 613220606065770495, 613220606103519231, 613220606093033471, 613220606097227775, 613220605581328383, 613220605585522687, 613220605390487551, 613220605394681855, 613220605432430591, 613220605421944831, 613220605426139135, 613220605849763839, 613220605411459071, 613220605667311615, 613220605656825855, 613220605661020159, 613220605698768895, 613220605702963199, 613220605675700223, 613220605679894527, 613220608083230719, 613220608072744959, 613220608076939263, 613220608114687999, 613220608118882303, 613220608091619327, 613220608095813631, 613220608351666175, 613220608341180415, 613220608353763327, 613220608326500351, 613220608330694655, 613220608368443391, 613220608357957631, 613220608362151935, 613220606604738559, 613220606608932863, 613220606581669887, 613220606585864191, 613220606623612927, 613220606613127167, 613220606617321471, 613220606873174015, 613220606877368319, 613220606850105343, 613220606848008191, 613220606852202495, 613220606889951231, 613220606894145535, 613221654100705279, 613221654104899583, 613221654025207807, 613221654014722047, 613221654018916351, 613221654056665087, 613221654060859391, 613221653429616639, 613221653433810943, 613221653354119167, 613221653343633407, 613221653347827711, 613221653385576447, 613221653450588159, 613221653706440703, 613221653695954943, 613221653700149247, 613221653620457471, 613221653624651775, 613221653714829311, 613221653719023615, 613221656122359807, 613221656111874047, 613221656116068351, 613221656036376575, 613221656040570879, 613221656130748415, 613221656134942719, 613221656390795263, 613221656388698111, 613221656392892415, 613221656365629439, 613221656369823743, 613221656407572479, 613221656397086719, 613221656401281023, 613221654643867647, 613221654648061951, 613221654620798975, 613221654624993279, 613221654662742015, 613221654652256255, 613221654656450559, 613221654912303103, 613221654916497407, 613221654889234431, 613221654887137279, 613221654891331583, 613221654929080319, 613221654933274623, 613221654738239487, 613221654742433791, 613221671272185855, 613221671261700095, 613221671265894399, 613221671303643135, 613221671307837439, 613221671112802303, 613221671116996607, 613221670601097215, 613221670590611455, 613221670594805759, 613221670632554495, 613221671351877631, 613221671389626367, 613221671379140607, 613221671383334911, 613221670867435519, 613221670871629823, 613221669602852863, 613221669607047167, 613221669644795903, 613221669634310143, 613221669638504447, 613221673283354623, 613221673287548927, 613221669871288319, 613221669875482623, 613221669913231359, 613221669911134207, 613221669915328511, 613221669888065535, 613221669892259839, 613221672295596031, 613221672285110271, 613221672289304575, 613221672327053311, 613221672331247615, 613221672303984639, 613221672308178943, 613221671624507391, 613221671614021631, 613221671618215935, 613221671655964671, 613221671660158975, 613221671632895999, 613221671630798847, 613221671634993151, 613221671890845695, 613221671895039999, 613221671867777023, 613221671871971327, 613221671909720063, 613221671899234303, 613221671903428607, 613221559416389631, 613221559420583935, 613221559393320959, 613221559397515263, 613221559435263999, 613221559424778239, 613221559428972543, 613221559684825087, 613221559749836799, 613221559670145023, 613221559659659263, 613221559663853567, 613221559701602303, 613221559705796607, 613221558000812031, 613221558005006335, 613221557925314559, 613221557914828799, 613221557919023103, 613221557956771839, 613221557960966143, 613221558269247487, 613221558273441791, 613221558193750015, 613221558191652863, 613221558195847167, 613221558286024703, 613221558290219007, 613221560693555199, 613221560683069439, 613221560687263743, 613221560607571967, 613221560611766271, 613221560701943807, 613221560706138111, 613221560022466559, 613221560011980799, 613221560016175103, 613221559936483327, 613221559940677631, 613221560030855167, 613221560028758015, 613221560032952319, 613221560288804863, 613221560292999167, 613221560265736191, 613221560269930495, 613221560307679231, 613221560297193471, 613221560301387775, 613221576663367679, 613221576667561983, 613221576640299007, 613221576644493311, 613221576682242047, 613221576671756287, 613221576675950591, 613221580784271359, 613221580788465663, 613221576917123071, 613221576906637311, 613221576910831615, 613221576948580351, 613221576952774655, 613221575683997695, 613221575688191999, 613221575172292607, 613221575161806847, 613221575166001151, 613221575203749887, 613221575207944191, 613221575012909055, 613221575017103359, 613221575440728063, 613221575438630911, 613221575442825215, 613221575247790079, 613221575251984383, 613221575289733119, 613221575279247359, 613221575283441663, 613221577854550015, 613221577858744319, 613221577663709183, 613221577667903487, 613221577705652223, 613221577695166463, 613221577699360767, 613221577183461375, 613221577187655679, 613221577932144639, 613221577930047487, 613221577934241791, 613221577971990527, 613221577976184831, 613221577948921855, 613221577953116159, 613221735109492735, 613221735099006975, 613221735103201279, 613221735140950015, 613221735145144319, 613221735117881343, 613221735122075647, 613221735377928191, 613221735367442431, 613221735371636735, 613221735352762367, 613221735356956671, 613221735394705407, 613221735384219647, 613221735388413951, 613221730275557375, 613221730279751679, 613221730252488703, 613221730256683007, 613221730294431743, 613221730283945983, 613221730288140287, 613221729604468735, 613221729608663039, 613221729581400063, 613221729585594367, 613221729623343103, 613221729621245951, 613221729625440255, 613221729933721599, 613221729937915903, 613221729858224127, 613221729847738367, 613221729851932671, 613221729889681407, 613221729893875711, 613221732349640703, 613221732353835007, 613221732274143231, 613221732263657471, 613221732267851775, 613221732305600511, 613221732309794815, 613221732626464767, 613221732615979007, 613221732620173311, 613221732540481535, 613221732544675839, 613221732634853375, 613221732639047679, 613221692226928639, 613221692216442879, 613221692220637183, 613221692140945407, 613221692145139711, 613221692235317247, 613221692239511551, 613221692495364095, 613221692484878335, 613221692489072639, 613221692470198271, 613221692474392575, 613221692512141311, 613221692501655551, 613221692505849855, 613221687392993279, 613221687397187583, 613221687369924607, 613221687374118911, 613221687411867647, 613221687401381887, 613221687405576191, 613221686721904639, 613221686726098943, 613221686698835967, 613221686703030271, 613221686740779007, 613221686738681855, 613221686742876159, 613221687487365119, 613221687491559423, 613221686975660031, 613221686965174271, 613221686969368575, 613221687007117311, 613221687011311615, 613221693258727423, 613221693262921727, 613221689391579135, 613221689381093375, 613221689385287679, 613221689423036415, 613221689427230719, 613221693535551487, 613221693525065727, 613221693529260031, 613221689657917439, 613221689662111743, 613221709868171263, 613221709872365567, 613221709910114303, 613221709899628543, 613221709903822847, 613221709387923455, 613221709392117759, 613221709197082623, 613221709201276927, 613221709239025663, 613221709228539903, 613221709232734207, 613221709213859839, 613221709218054143, 613221709473906687, 613221709463420927, 613221709467615231, 613221709505363967, 613221709509558271, 613221709482295295, 613221709486489599, 613221704373633023, 613221704363147263, 613221704367341567, 613221704405090303, 613221704409284607, 613221704382021631, 613221704386215935, 613221704642068479, 613221704639971327, 613221704644165631, 613221704616902655, 613221704621096959, 613221704658845695, 613221704648359935, 613221704652554239, 613221710411333631, 613221710415527935, 613221710388264959, 613221710392459263, 613221710430207999, 613221710419722239, 613221710423916543, 613221710679769087, 613221710683963391, 613221710665089023, 613221710654603263, 613221710658797567, 613221710696546303, 613221710700740607, 613168113669636095, 613168113665441791, 613168113627693055, 613168113623498751, 613168113633984511, 613168113713676287, 613168113709481983, 613168113401200639, 613168113397006335, 613168113359257599, 613168113355063295, 613168113365549055, 613168113384423423, 613168113380229119, 613168114063900671, 613168114059706367, 613168114070192127, 613168114032443391, 613168114028249087, 613168114055512063, 613168114051317759, 613168111647981567, 613168111643787263, 613168111654273023, 613168111616524287, 613168111612329983, 613168111639592959, 613168111635398655, 613168111637495807, 613168111381643263, 613168111377448959, 613168111404711935, 613168111400517631, 613168111362768895, 613168111358574591, 613168111369060351, 613168113126473727, 613168113122279423, 613168113149542399, 613168113145348095, 613168113107599359, 613168113103405055, 613168113113890815, 613168112858038271, 613168112853843967, 613168112872718335, 613168112868524031, 613168112879009791, 613168112841261055, 613168112837066751, 613168113032101887, 613168113027907583, 613168096498155519, 613168096493961215, 613168096504446975, 613168096466698239, 613168096462503935, 613168096657539071, 613168096653344767, 613168096229720063, 613168096225525759, 613168096236011519, 613168096422658047, 613168096418463743, 613168096380715007, 613168096376520703, 613168096387006463, 613168096902905855, 613168096898711551, 613168098167488511, 613168098163294207, 613168098125545471, 613168098121351167, 613168098131836927, 613168094486986751, 613168094482792447, 613168097899053055, 613168097894858751, 613168097896955903, 613168097859207167, 613168097855012863, 613168097882275839, 613168097878081535, 613168095474745343, 613168095470551039, 613168095481036799, 613168095443288063, 613168095439093759, 613168095466356735, 613168095462162431, 613168095206309887, 613168095202115583, 613168095212601343, 613168095174852607, 613168095170658303, 613168095189532671, 613168095185338367, 613168095195824127, 613168095879495679, 613168095875301375, 613168095785123839, 613168095780929535, 613168095860621311, 613168095856427007, 613168095866912767, 613168208353951743, 613168208349757439, 613168208259579903, 613168208255385599, 613168208335077375, 613168208330883071, 613168208341368831, 613168208024698879, 613168208020504575, 613168207982755839, 613168207978561535, 613168207989047295, 613168208068739071, 613168208064544767, 613168209769529343, 613168209765335039, 613168209727586303, 613168209723391999, 613168209733877759, 613168209813569535, 613168209809375231, 613168209501093887, 613168209496899583, 613168209498996735, 613168209461247999, 613168209457053695, 613168209484316671, 613168209480122367, 613168207076786175, 613168207072591871, 613168207083077631, 613168207045328895, 613168207041134591, 613168207068397567, 613168207064203263, 613168206808350719, 613168206804156415, 613168206814642175, 613168206776893439, 613168206772699135, 613168206791573503, 613168206787379199, 613168206797864959, 613168207481536511, 613168207477342207, 613168207504605183, 613168207500410879, 613168207462662143, 613168207458467839, 613168207468953599, 613168191106973695, 613168191102779391, 613168191130042367, 613168191125848063, 613168191088099327, 613168191083905023, 613168191086002175, 613168159068782591, 613168159064588287, 613168190853218303, 613168190849023999, 613168190859509759, 613168190821761023, 613168190817566719, 613168192086343679, 613168192082149375, 613168192598048767, 613168192593854463, 613168192604340223, 613168192566591487, 613168192562397183, 613168191817908223, 613168191813713919, 613168191815811071, 613168192331710463, 613168192327516159, 613168192522551295, 613168192518356991, 613168192480608255, 613168192476413951, 613168192486899711, 613168189915791359, 613168189911597055, 613168190106632191, 613168190102437887, 613168190064689151, 613168190060494847, 613168190070980607, 613168189647355903, 613168189643161599, 613168189829808127, 613168189825613823, 613168189836099583, 613168189798350847, 613168189794156543, 613168189821419519, 613168189817225215, 613168202312056831, 613168202307862527, 613168202318348287, 613168202280599551, 613168202276405247, 613168202303668223, 613168202299473919, 613168202043621375, 613168202039427071, 613168202041524223, 613168201951346687, 613168201947152383, 613168202026844159, 613168202022649855, 613168202033135615, 613168037494783999, 613168037490589695, 613168037400412159, 613168037396217855, 613168037475909631, 613168037471715327, 613168037482201087, 613168037226348543, 613168037222154239, 613168037131976703, 613168037127782399, 613168037129879551, 613168037209571327, 613168037205377023, 613168037836619775, 613168037832425471, 613168037794676735, 613168037790482431, 613168037800968191, 613168037880659967, 613168037876465663, 613168035420700671, 613168035416506367, 613168035378757631, 613168035374563327, 613168035385049087, 613168035464740863, 613168035399729151, 613168035143876607, 613168035139682303, 613168035150168063, 613168035112419327, 613168035108225023, 613168035135487999, 613168035131293695, 613168047626125311, 613168047621931007, 613168047632416767, 613168047594668031, 613168047590473727, 613168047617736703, 613168047613542399, 613168047357689855, 613168047353495551, 613168047355592703, 613168047382855679, 613168047378661375, 613168047340912639, 613168047336718335, 613168047347204095, 613168020247805951, 613168020243611647, 613168020270874623, 613168020266680319, 613168020228931583, 613168020224737279, 613168020235223039, 613168019979370495, 613168019975176191, 613168020002439167, 613168019998244863, 613168020000342015, 613168019962593279, 613168019958398975, 613168020153434111, 613168020149239807, 613168020665139199, 613168020660944895, 613168020671430655, 613168020633681919, 613168020629487615, 613168032635682815, 613168032631488511, 613168018249220095, 613168018245025791, 613168018255511551, 613168018217762815, 613168032396607487, 613168032358858751, 613168032354664447, 613168032365150207, 613168017982881791, 613168017978687487, 613168029984882687, 613168029980688383, 613168029942939647, 613168029938745343, 613168029949231103, 613168030465130495, 613168030460936191, 613168029716447231, 613168029712252927, 613168029674504191, 613168029670309887, 613168029672407039, 613168029699670015, 613168029695475711, 613168030379147263, 613168030374952959, 613168030385438719, 613168030347689983, 613168030343495679, 613168030370758655, 613168030366564351, 613168063396708351, 613168063392514047, 613168063402999807, 613168063365251071, 613168063361056767, 613168063388319743, 613168063384125439, 613168063386222591, 613168063130370047, 613168063126175743, 613168063035998207, 613168063031803903, 613168063111495679, 613168063107301375, 613168063117787135, 613168831526862847, 613168831522668543, 613168831432491007, 613168831428296703, 613168831507988479, 613168831503794175, 613168831514279935, 613168831258427391, 613168831193415679, 613168831155666943, 613168831151472639, 613168831161958399, 613168831241650175, 613168831237455871, 613168828781690879, 613168828777496575, 613168828739747839, 613168828735553535, 613168828746039295, 613168828825731071, 613168828821536767, 613168828513255423, 613168828509061119, 613168828471312383, 613168828467118079, 613168828469215231, 613168828496478207, 613168828492283903, 613168829175955455, 613168829171761151, 613168829182246911, 613168829144498175, 613168829140303871, 613168829167566847, 613168829163372543, 613167015357579263, 613167015353384959, 613167015363870719, 613167015326121983, 613167015321927679, 613167015349190655, 613167015336607743, 613167015347093503, 613167015091240959, 613167015087046655, 613167015114309631, 613167015110115327, 613167015072366591, 613167015068172287, 613167015078658047, 613168814279884799, 613168814275690495, 613168814302953471, 613168814298759167, 613168814261010431, 613168814256816127, 613168814267301887, 613168814011449343, 613168813510230015, 613168814026129407, 613168814021935103, 613168814032420863, 613168813994672127, 613168813990477823, 613168814185512959, 613168814181318655, 613168811610210303, 613168811606015999, 613168811616501759, 613168811578753023, 613168811574558719, 613168811769593855, 613168811765399551, 613168811341774847, 613168811337580543, 613168811339677695, 613168811534712831, 613168811530518527, 613168811492769791, 613168811488575487, 613168811499061247, 613168812014960639, 613168812010766335, 613168813279543295, 613168813275348991, 613168813237600255, 613168813233405951, 613168813243891711, 613166998196584447, 613166998192390143, 613168813011107839, 613168812998524927, 613168813009010687, 613168812971261951, 613168812967067647, 613168812994330623, 613168812990136319, 613167078641238015, 613167078637043711, 613167078647529471, 613167078609780735, 613167078605586431, 613167078632849407, 613167078628655103, 613167078372802559, 613167078368608255, 613167078379094015, 613167078341345279, 613167078276333567, 613167078356025343, 613167078351831039, 613167078362316799, 613167079045988351, 613167079041794047, 613167078951616511, 613167078947422207, 613167079027113983, 613167079022919679, 613167079033405439, 613167076630069247, 613167076625874943, 613167076535697407, 613167076531503103, 613167076611194879, 613167076607000575, 613167076609097727, 613167076300816383, 613167076296622079, 613167076258873343, 613167076254679039, 613167076265164799, 613167076344856575, 613167076340662271, 613167078045646847, 613167078041452543, 613167078003703807, 613167077999509503, 613167078009995263, 613167078089687039, 613167078085492735, 613167077777211391, 613167077764628479, 613167077775114239, 613167077737365503, 613167077733171199, 613167077760434175, 613167077756239871, 613167061394259967, 613167061390065663, 613167061400551423, 613167061362802687, 613167061358608383, 613167061385871359, 613167061381677055, 613167061125824511, 613167061121630207, 613167061132115967, 613167061094367231, 613167061146796031, 613167061109047295, 613167061104852991, 613167061115338751, 613167061799010303, 613167061794815999, 613167061822078975, 613167061817884671, 613167061780135935, 613167061775941631, 613167061786427391, 613167059383091199, 613167059378896895, 613167059406159871, 613167059401965567, 613167059364216831, 613167059366313983, 613167059362119679, 613167055262187519, 613167055257993215, 613167059129335807, 613167059125141503, 613167059135627263, 613167059097878527, 613167059093684223, 613167060362461183, 613167060358266879, 613167060874166271, 613167060869971967, 613167060880457727, 613167060842708991, 613167060838514687, 613167060094025727, 613167060081442815, 613167060091928575, 613167060607827967, 613167060603633663, 613167060798668799, 613167060794474495, 613167060756725759, 613167060752531455, 613167060763017215, 613167104362807295, 613167104358612991, 613167104553648127, 613167104549453823, 613167104511705087, 613167104507510783, 613167104517996543, 613167104094371839, 613167104532676607, 613167104276824063, 613167104272629759, 613167104283115519, 613167104245366783, 613167104241172479, 613167104268435455, 613167104264241151, 613167098505461759, 613167098501267455, 613167098511753215, 613167098474004479, 613167098469810175, 613167098497073151, 613167098492878847, 613167098237026303, 613167098239123455, 613167098234929151, 613167098144751615, 613167098140557311, 613167098220249087, 613167098216054783, 613167098226540543, 613167103339397119, 613167103335202815, 613167103245025279, 613167103240830975, 613167103320522751, 613167103316328447, 613167103326814207, 613167103070961663, 613167103066767359, 613167102976589823, 613167102964006911, 613167102974492671, 613167103054184447, 613167103049990143, 613167103681232895, 613167103677038591, 613167103639289855, 613167103635095551, 613167103645581311, 613167103725273087, 613167103721078783, 613166949867716607, 613166949863522303, 613166949825773567, 613166949821579263, 613166949832065023, 613166949850939391, 613166949846745087, 613166949590892543, 613166949586698239, 613166949597183999, 613166949559435263, 613166949555240959, 613166949582503935, 613166949578309631, 613166943819530239, 613166943815335935, 613166943825821695, 613166943788072959, 613166943783878655, 613166943811141631, 613166943806947327, 613166943551094783, 613166943553191935, 613166943548997631, 613166943576260607, 613166943572066303, 613166943534317567, 613166943530123263, 613166943540609023, 613166948653465599, 613166948649271295, 613166948676534271, 613166948672339967, 613166948634591231, 613166948630396927, 613166948640882687, 613166948385030143, 613166948380835839, 613166948408098815, 613166948395515903, 613166948406001663, 613166948368252927, 613166948364058623, 613166948559093759, 613166948554899455, 613166949070798847, 613166949066604543, 613166949077090303, 613166949039341567, 613166949035147263, 613166928829087743, 613166928824893439, 613166932696236031, 613166932692041727, 613166932702527487, 613166928594206719, 613166928590012415, 613166928552263679, 613166928548069375, 613166928558555135, 613166932429897727, 613166932425703423, 613166926178287615, 613166926174093311, 613166926136344575, 613166926132150271, 613166926142636031, 613166926658535423, 613166926654341119, 613166925909852159, 613166925905657855, 613166925867909119, 613166925870006271, 613166925865811967, 613166925893074943, 613166925888880639, 613166926572552191, 613166926568357887, 613166926578843647, 613166926541094911, 613166926536900607, 613166926564163583, 613166926559969279, 613166931672825855, 613166931668631551, 613166931679117311, 613166931641368575, 613166931637174271, 613166931664437247, 613166931651854335, 613166931662340095, 613166931406487551, 613166931402293247, 613166931312115711, 613166931307921407, 613166931387613183, 613166931383418879, 613166931393904639, 613167727720267775, 613167727716073471, 613167727625895935, 613167727621701631, 613167727701393407, 613167727697199103, 613167727707684863, 613167727391014911, 613167727386820607, 613167727349071871, 613167727344877567, 613167727355363327, 613167727435055103, 613167727430860799, 613167724975095807, 613167724970901503] | ++----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ + SELECT geohash(37.76938, -122.3889, 9); +--------------------------------------------------------+ diff --git a/tests/cases/standalone/common/function/geo.sql b/tests/cases/standalone/common/function/geo.sql index 3ce1863c863..3f47465bfdb 100644 --- a/tests/cases/standalone/common/function/geo.sql +++ b/tests/cases/standalone/common/function/geo.sql @@ -39,6 +39,22 @@ SELECT h3_child_pos_to_cell(25, cell, 11) AS child FROM (SELECT h3_latlng_to_cell(37.76938, -122.3889, 8::UInt64) AS cell); +SELECT + h3_grid_disk(cell, 0) AS current_cell, + h3_grid_disk(cell, 3) AS grids, + h3_grid_disk_distances(cell, 3) AS all_grids, +FROM (SELECT h3_latlng_to_cell(37.76938, -122.3889, 8::UInt64) AS cell); + +SELECT + h3_grid_distance(cell1, cell2) AS distance, + h3_grid_path_cells(cell1, cell2) AS path_cells, +FROM + ( + SELECT + h3_latlng_to_cell(37.76938, -122.3889, 8::UInt64) AS cell1, + h3_latlng_to_cell(39.634, -104.999, 8::UInt64) AS cell2 + ); + SELECT geohash(37.76938, -122.3889, 9); SELECT geohash(37.76938, -122.3889, 10); From 5d93d3793f96cc646a02599a47efa89c0ab3fd5e Mon Sep 17 00:00:00 2001 From: Ning Sun Date: Thu, 26 Sep 2024 17:12:35 -0700 Subject: [PATCH 3/7] refactor: update some function definitions --- src/common/function/src/scalars/geo.rs | 3 +- src/common/function/src/scalars/geo/h3.rs | 97 ++++++------------- .../standalone/common/function/geo.result | 12 +-- .../cases/standalone/common/function/geo.sql | 2 +- 4 files changed, 40 insertions(+), 74 deletions(-) diff --git a/src/common/function/src/scalars/geo.rs b/src/common/function/src/scalars/geo.rs index e41e934efbf..e2a1d8422d5 100644 --- a/src/common/function/src/scalars/geo.rs +++ b/src/common/function/src/scalars/geo.rs @@ -37,8 +37,7 @@ impl GeoFunctions { registry.register(Arc::new(h3::H3CellIsPentagon)); registry.register(Arc::new(h3::H3StringToCell)); registry.register(Arc::new(h3::H3CellToString)); - registry.register(Arc::new(h3::H3CellCenterLat)); - registry.register(Arc::new(h3::H3CellCenterLng)); + registry.register(Arc::new(h3::H3CellCenterLatLng)); registry.register(Arc::new(h3::H3CellResolution)); // h3 hierarchical grid diff --git a/src/common/function/src/scalars/geo/h3.rs b/src/common/function/src/scalars/geo/h3.rs index 26b21cc297c..b5e40da304f 100644 --- a/src/common/function/src/scalars/geo/h3.rs +++ b/src/common/function/src/scalars/geo/h3.rs @@ -23,8 +23,8 @@ use datatypes::prelude::ConcreteDataType; use datatypes::scalars::{Scalar, ScalarVectorBuilder}; use datatypes::value::{ListValue, Value}; use datatypes::vectors::{ - BooleanVectorBuilder, Float64VectorBuilder, Int32VectorBuilder, ListVectorBuilder, - MutableVector, StringVectorBuilder, UInt64VectorBuilder, UInt8VectorBuilder, VectorRef, + BooleanVectorBuilder, Int32VectorBuilder, ListVectorBuilder, MutableVector, + StringVectorBuilder, UInt64VectorBuilder, UInt8VectorBuilder, VectorRef, }; use derive_more::Display; use h3o::{CellIndex, LatLng, Resolution}; @@ -319,18 +319,20 @@ impl Function for H3StringToCell { } } -/// Function that returns centroid latitude of given cell id +/// Function that returns centroid latitude and longitude of given cell id #[derive(Clone, Debug, Default, Display)] #[display("{}", self.name())] -pub struct H3CellCenterLat; +pub struct H3CellCenterLatLng; -impl Function for H3CellCenterLat { +impl Function for H3CellCenterLatLng { fn name(&self) -> &str { - "h3_cell_center_lat" + "h3_cell_center_latlng" } fn return_type(&self, _input_types: &[ConcreteDataType]) -> Result { - Ok(ConcreteDataType::float64_datatype()) + Ok(ConcreteDataType::list_datatype( + ConcreteDataType::float64_datatype(), + )) } fn signature(&self) -> Signature { @@ -350,57 +352,22 @@ impl Function for H3CellCenterLat { let cell_vec = &columns[0]; let size = cell_vec.len(); - let mut results = Float64VectorBuilder::with_capacity(size); + let mut results = + ListVectorBuilder::with_type_capacity(ConcreteDataType::float64_datatype(), size); for i in 0..size { let cell = cell_from_value(cell_vec.get(i))?; - let lat = cell.map(|cell| LatLng::from(cell).lat()); - - results.push(lat); - } - - Ok(results.to_vector()) - } -} - -/// Function that returns centroid longitude of given cell id -#[derive(Clone, Debug, Default, Display)] -#[display("{}", self.name())] -pub struct H3CellCenterLng; - -impl Function for H3CellCenterLng { - fn name(&self) -> &str { - "h3_cell_center_lng" - } - - fn return_type(&self, _input_types: &[ConcreteDataType]) -> Result { - Ok(ConcreteDataType::float64_datatype()) - } - - fn signature(&self) -> Signature { - signature_of_cell() - } - - fn eval(&self, _func_ctx: FunctionContext, columns: &[VectorRef]) -> Result { - ensure!( - columns.len() == 1, - InvalidFuncArgsSnafu { - err_msg: format!( - "The length of the args is not correct, expect 1, provided : {}", - columns.len() - ), + let latlng = cell.map(LatLng::from); + + if let Some(latlng) = latlng { + let result = ListValue::new( + vec![latlng.lat().into(), latlng.lng().into()], + ConcreteDataType::float64_datatype(), + ); + results.push(Some(result.as_scalar_ref())); + } else { + results.push(None); } - ); - - let cell_vec = &columns[0]; - let size = cell_vec.len(); - let mut results = Float64VectorBuilder::with_capacity(size); - - for i in 0..size { - let cell = cell_from_value(cell_vec.get(i))?; - let lat = cell.map(|cell| LatLng::from(cell).lng()); - - results.push(lat); } Ok(results.to_vector()) @@ -673,15 +640,15 @@ impl Function for H3CellToChildren { for i in 0..size { let cell = cell_from_value(cell_vec.get(i))?; let res = value_to_resolution(res_vec.get(i))?; - let result = cell.and_then(|cell| { + let result = cell.map(|cell| { let children: Vec = cell .children(res) .map(|child| Value::from(u64::from(child))) .collect(); - Some(ListValue::new( + ListValue::new( children, ConcreteDataType::uint64_datatype(), - )) + ) }); if let Some(list_value) = result { @@ -906,16 +873,16 @@ impl Function for H3GridDisk { let cell = cell_from_value(cell_vec.get(i))?; let k = value_to_distance(k_vec.get(i))?; - let result = cell.and_then(|cell| { + let result = cell.map(|cell| { let children: Vec = cell .grid_disk::>(k) .into_iter() .map(|child| Value::from(u64::from(child))) .collect(); - Some(ListValue::new( + ListValue::new( children, ConcreteDataType::uint64_datatype(), - )) + ) }); if let Some(list_value) = result { @@ -970,16 +937,16 @@ impl Function for H3GridDiskDistances { let cell = cell_from_value(cell_vec.get(i))?; let k = value_to_distance(k_vec.get(i))?; - let result = cell.and_then(|cell| { + let result = cell.map(|cell| { let children: Vec = cell .grid_disk_distances::>(k) .into_iter() .map(|(child, _distance)| Value::from(u64::from(child))) .collect(); - Some(ListValue::new( + ListValue::new( children, ConcreteDataType::uint64_datatype(), - )) + ) }); if let Some(list_value) = result { @@ -1179,7 +1146,7 @@ fn value_to_position(v: Value) -> Result { Value::UInt8(v) => Ok(v as u64), Value::UInt16(v) => Ok(v as u64), Value::UInt32(v) => Ok(v as u64), - Value::UInt64(v) => Ok(v as u64), + Value::UInt64(v) => Ok(v), _ => unreachable!(), } } @@ -1192,7 +1159,7 @@ fn value_to_distance(v: Value) -> Result { Value::Int64(v) => ensure_and_coerce!(v >= 0, v as u32), Value::UInt8(v) => Ok(v as u32), Value::UInt16(v) => Ok(v as u32), - Value::UInt32(v) => Ok(v as u32), + Value::UInt32(v) => Ok(v), Value::UInt64(v) => Ok(v as u32), _ => unreachable!(), } diff --git a/tests/cases/standalone/common/function/geo.result b/tests/cases/standalone/common/function/geo.result index 21caf3c8994..e63ba19de6b 100644 --- a/tests/cases/standalone/common/function/geo.result +++ b/tests/cases/standalone/common/function/geo.result @@ -102,13 +102,13 @@ SELECT h3_cell_to_string(h3_latlng_to_cell(37.76938, -122.3889, 8::UInt64)) AS c | 88283082e7fffff | 613196570438926335 | +-----------------+--------------------+ -SELECT h3_cell_center_lat(h3_latlng_to_cell(37.76938, -122.3889, 8::UInt64)) AS cell_center_lat, h3_cell_center_lng(h3_latlng_to_cell(37.76938, -122.3889, 8::UInt64)) AS cell_center_lng; +SELECT h3_cell_center_latlng(h3_latlng_to_cell(37.76938, -122.3889, 8::UInt64)) AS cell_center; -+-------------------+---------------------+ -| cell_center_lat | cell_center_lng | -+-------------------+---------------------+ -| 37.77246152245501 | -122.39010997087324 | -+-------------------+---------------------+ ++------------------------------------------+ +| cell_center | ++------------------------------------------+ +| [37.77246152245501, -122.39010997087324] | ++------------------------------------------+ SELECT h3_cell_resolution(cell) AS resolution, diff --git a/tests/cases/standalone/common/function/geo.sql b/tests/cases/standalone/common/function/geo.sql index 3f47465bfdb..ed626944674 100644 --- a/tests/cases/standalone/common/function/geo.sql +++ b/tests/cases/standalone/common/function/geo.sql @@ -26,7 +26,7 @@ SELECT h3_latlng_to_cell(37.76938, -122.3889, 8::UInt64), h3_latlng_to_cell_stri SELECT h3_cell_to_string(h3_latlng_to_cell(37.76938, -122.3889, 8::UInt64)) AS cell_str, h3_string_to_cell(h3_latlng_to_cell_string(37.76938, -122.3889, 8::UInt64)) AS cell_index; -SELECT h3_cell_center_lat(h3_latlng_to_cell(37.76938, -122.3889, 8::UInt64)) AS cell_center_lat, h3_cell_center_lng(h3_latlng_to_cell(37.76938, -122.3889, 8::UInt64)) AS cell_center_lng; +SELECT h3_cell_center_latlng(h3_latlng_to_cell(37.76938, -122.3889, 8::UInt64)) AS cell_center; SELECT h3_cell_resolution(cell) AS resolution, From 80c5f0ed88e16ea016e50ad8dba65607602c34e3 Mon Sep 17 00:00:00 2001 From: Ning Sun Date: Thu, 26 Sep 2024 18:54:07 -0700 Subject: [PATCH 4/7] style: format --- src/common/function/src/scalars/geo/h3.rs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/common/function/src/scalars/geo/h3.rs b/src/common/function/src/scalars/geo/h3.rs index b5e40da304f..6361d71316d 100644 --- a/src/common/function/src/scalars/geo/h3.rs +++ b/src/common/function/src/scalars/geo/h3.rs @@ -645,10 +645,7 @@ impl Function for H3CellToChildren { .children(res) .map(|child| Value::from(u64::from(child))) .collect(); - ListValue::new( - children, - ConcreteDataType::uint64_datatype(), - ) + ListValue::new(children, ConcreteDataType::uint64_datatype()) }); if let Some(list_value) = result { @@ -879,10 +876,7 @@ impl Function for H3GridDisk { .into_iter() .map(|child| Value::from(u64::from(child))) .collect(); - ListValue::new( - children, - ConcreteDataType::uint64_datatype(), - ) + ListValue::new(children, ConcreteDataType::uint64_datatype()) }); if let Some(list_value) = result { @@ -943,10 +937,7 @@ impl Function for H3GridDiskDistances { .into_iter() .map(|(child, _distance)| Value::from(u64::from(child))) .collect(); - ListValue::new( - children, - ConcreteDataType::uint64_datatype(), - ) + ListValue::new(children, ConcreteDataType::uint64_datatype()) }); if let Some(list_value) = result { From acf9f5b0a0c48f162f84e4dff2c7df82b597513c Mon Sep 17 00:00:00 2001 From: Ning Sun Date: Mon, 30 Sep 2024 14:56:15 -0700 Subject: [PATCH 5/7] refactor: avoid creating slice in nested loop --- src/common/function/src/scalars/geo/h3.rs | 158 +++++++++------------- 1 file changed, 67 insertions(+), 91 deletions(-) diff --git a/src/common/function/src/scalars/geo/h3.rs b/src/common/function/src/scalars/geo/h3.rs index 6361d71316d..c94c8575e54 100644 --- a/src/common/function/src/scalars/geo/h3.rs +++ b/src/common/function/src/scalars/geo/h3.rs @@ -28,10 +28,62 @@ use datatypes::vectors::{ }; use derive_more::Display; use h3o::{CellIndex, LatLng, Resolution}; +use once_cell::sync::Lazy; use snafu::{ensure, ResultExt}; use crate::function::{Function, FunctionContext}; +const CELL_TYPES: Lazy> = Lazy::new(|| { + vec![ + ConcreteDataType::int64_datatype(), + ConcreteDataType::uint64_datatype(), + ] +}); + +const COORDINATE_TYPES: Lazy> = Lazy::new(|| { + vec![ + ConcreteDataType::float32_datatype(), + ConcreteDataType::float64_datatype(), + ] +}); +const RESOLUTION_TYPES: Lazy> = Lazy::new(|| { + vec![ + ConcreteDataType::int8_datatype(), + ConcreteDataType::int16_datatype(), + ConcreteDataType::int32_datatype(), + ConcreteDataType::int64_datatype(), + ConcreteDataType::uint8_datatype(), + ConcreteDataType::uint16_datatype(), + ConcreteDataType::uint32_datatype(), + ConcreteDataType::uint64_datatype(), + ] +}); +const DISTANCE_TYPES: Lazy> = Lazy::new(|| { + vec![ + ConcreteDataType::int8_datatype(), + ConcreteDataType::int16_datatype(), + ConcreteDataType::int32_datatype(), + ConcreteDataType::int64_datatype(), + ConcreteDataType::uint8_datatype(), + ConcreteDataType::uint16_datatype(), + ConcreteDataType::uint32_datatype(), + ConcreteDataType::uint64_datatype(), + ] +}); + +const POSITION_TYPES: Lazy> = Lazy::new(|| { + vec![ + ConcreteDataType::int8_datatype(), + ConcreteDataType::int16_datatype(), + ConcreteDataType::int32_datatype(), + ConcreteDataType::int64_datatype(), + ConcreteDataType::uint8_datatype(), + ConcreteDataType::uint16_datatype(), + ConcreteDataType::uint32_datatype(), + ConcreteDataType::uint64_datatype(), + ] +}); + /// Function that returns [h3] encoding cellid for a given geospatial coordinate. /// /// [h3]: https://h3geo.org/ @@ -50,20 +102,8 @@ impl Function for H3LatLngToCell { fn signature(&self) -> Signature { let mut signatures = Vec::new(); - for coord_type in &[ - ConcreteDataType::float32_datatype(), - ConcreteDataType::float64_datatype(), - ] { - for resolution_type in &[ - ConcreteDataType::int8_datatype(), - ConcreteDataType::int16_datatype(), - ConcreteDataType::int32_datatype(), - ConcreteDataType::int64_datatype(), - ConcreteDataType::uint8_datatype(), - ConcreteDataType::uint16_datatype(), - ConcreteDataType::uint32_datatype(), - ConcreteDataType::uint64_datatype(), - ] { + for coord_type in COORDINATE_TYPES.as_slice() { + for resolution_type in RESOLUTION_TYPES.as_slice() { signatures.push(TypeSignature::Exact(vec![ // latitude coord_type.clone(), @@ -142,20 +182,8 @@ impl Function for H3LatLngToCellString { fn signature(&self) -> Signature { let mut signatures = Vec::new(); - for coord_type in &[ - ConcreteDataType::float32_datatype(), - ConcreteDataType::float64_datatype(), - ] { - for resolution_type in &[ - ConcreteDataType::int8_datatype(), - ConcreteDataType::int16_datatype(), - ConcreteDataType::int32_datatype(), - ConcreteDataType::int64_datatype(), - ConcreteDataType::uint8_datatype(), - ConcreteDataType::uint16_datatype(), - ConcreteDataType::uint32_datatype(), - ConcreteDataType::uint64_datatype(), - ] { + for coord_type in COORDINATE_TYPES.as_slice() { + for resolution_type in RESOLUTION_TYPES.as_slice() { signatures.push(TypeSignature::Exact(vec![ // latitude coord_type.clone(), @@ -765,30 +793,9 @@ impl Function for H3ChildPosToCell { fn signature(&self) -> Signature { let mut signatures = Vec::new(); - for position_type in &[ - ConcreteDataType::int8_datatype(), - ConcreteDataType::int16_datatype(), - ConcreteDataType::int32_datatype(), - ConcreteDataType::int64_datatype(), - ConcreteDataType::uint8_datatype(), - ConcreteDataType::uint16_datatype(), - ConcreteDataType::uint32_datatype(), - ConcreteDataType::uint64_datatype(), - ] { - for cell_type in &[ - ConcreteDataType::uint64_datatype(), - ConcreteDataType::int64_datatype(), - ] { - for resolution_type in &[ - ConcreteDataType::int8_datatype(), - ConcreteDataType::int16_datatype(), - ConcreteDataType::int32_datatype(), - ConcreteDataType::int64_datatype(), - ConcreteDataType::uint8_datatype(), - ConcreteDataType::uint16_datatype(), - ConcreteDataType::uint32_datatype(), - ConcreteDataType::uint64_datatype(), - ] { + for position_type in POSITION_TYPES.as_slice() { + for cell_type in CELL_TYPES.as_slice() { + for resolution_type in RESOLUTION_TYPES.as_slice() { signatures.push(TypeSignature::Exact(vec![ position_type.clone(), cell_type.clone(), @@ -1158,10 +1165,7 @@ fn value_to_distance(v: Value) -> Result { fn signature_of_cell() -> Signature { let mut signatures = Vec::new(); - for cell_type in &[ - ConcreteDataType::uint64_datatype(), - ConcreteDataType::int64_datatype(), - ] { + for cell_type in CELL_TYPES.as_slice() { signatures.push(TypeSignature::Exact(vec![cell_type.clone()])); } @@ -1170,12 +1174,8 @@ fn signature_of_cell() -> Signature { fn signature_of_double_cells() -> Signature { let mut signatures = Vec::new(); - let cell_types = &[ - ConcreteDataType::uint64_datatype(), - ConcreteDataType::int64_datatype(), - ]; - for cell_type in cell_types { - for cell_type2 in cell_types { + for cell_type in CELL_TYPES.as_slice() { + for cell_type2 in CELL_TYPES.as_slice() { signatures.push(TypeSignature::Exact(vec![ cell_type.clone(), cell_type2.clone(), @@ -1188,20 +1188,8 @@ fn signature_of_double_cells() -> Signature { fn signature_of_cell_and_resolution() -> Signature { let mut signatures = Vec::new(); - for cell_type in &[ - ConcreteDataType::uint64_datatype(), - ConcreteDataType::int64_datatype(), - ] { - for resolution_type in &[ - ConcreteDataType::int8_datatype(), - ConcreteDataType::int16_datatype(), - ConcreteDataType::int32_datatype(), - ConcreteDataType::int64_datatype(), - ConcreteDataType::uint8_datatype(), - ConcreteDataType::uint16_datatype(), - ConcreteDataType::uint32_datatype(), - ConcreteDataType::uint64_datatype(), - ] { + for cell_type in CELL_TYPES.as_slice() { + for resolution_type in RESOLUTION_TYPES.as_slice() { signatures.push(TypeSignature::Exact(vec![ cell_type.clone(), resolution_type.clone(), @@ -1213,23 +1201,11 @@ fn signature_of_cell_and_resolution() -> Signature { fn signature_of_cell_and_distance() -> Signature { let mut signatures = Vec::new(); - for cell_type in &[ - ConcreteDataType::uint64_datatype(), - ConcreteDataType::int64_datatype(), - ] { - for resolution_type in &[ - ConcreteDataType::int8_datatype(), - ConcreteDataType::int16_datatype(), - ConcreteDataType::int32_datatype(), - ConcreteDataType::int64_datatype(), - ConcreteDataType::uint8_datatype(), - ConcreteDataType::uint16_datatype(), - ConcreteDataType::uint32_datatype(), - ConcreteDataType::uint64_datatype(), - ] { + for cell_type in CELL_TYPES.as_slice() { + for distance_type in DISTANCE_TYPES.as_slice() { signatures.push(TypeSignature::Exact(vec![ cell_type.clone(), - resolution_type.clone(), + distance_type.clone(), ])); } } From 33aa437ad1c825d14dfac6af63b0a7e8194d8e09 Mon Sep 17 00:00:00 2001 From: Ning Sun Date: Mon, 30 Sep 2024 16:37:12 -0700 Subject: [PATCH 6/7] feat: ensure column number and length --- src/common/function/src/scalars/geo/h3.rs | 214 ++++++---------------- 1 file changed, 61 insertions(+), 153 deletions(-) diff --git a/src/common/function/src/scalars/geo/h3.rs b/src/common/function/src/scalars/geo/h3.rs index c94c8575e54..48b33623071 100644 --- a/src/common/function/src/scalars/geo/h3.rs +++ b/src/common/function/src/scalars/geo/h3.rs @@ -84,6 +84,50 @@ const POSITION_TYPES: Lazy> = Lazy::new(|| { ] }); +macro_rules! ensure_columns_len { + ($columns:ident) => { + ensure!( + $columns.windows(2).all(|c| c[0].len() == c[1].len()), + InvalidFuncArgsSnafu { + err_msg: "The length of input columns are in different size" + } + ) + }; + ($column_a:ident, $column_b:ident, $($column_n:ident),*) => { + ensure!( + { + let mut result = $column_a.len() == $column_b.len(); + $( + result = result && ($column_a.len() == $column_n.len()); + )* + result + } + InvalidFuncArgsSnafu { + err_msg: "The length of input columns are in different size" + } + ) + }; +} + +macro_rules! ensure_columns_n { + ($columns:ident, $n:literal) => { + ensure!( + $columns.len() == $n, + InvalidFuncArgsSnafu { + err_msg: format!( + "The length of arguments is not correct, expect {}, provided : {}", + stringify!($n), + $columns.len() + ), + } + ); + + if $n > 1 { + ensure_columns_len!($columns); + } + }; +} + /// Function that returns [h3] encoding cellid for a given geospatial coordinate. /// /// [h3]: https://h3geo.org/ @@ -118,15 +162,7 @@ impl Function for H3LatLngToCell { } fn eval(&self, _func_ctx: FunctionContext, columns: &[VectorRef]) -> Result { - ensure!( - columns.len() == 3, - InvalidFuncArgsSnafu { - err_msg: format!( - "The length of the args is not correct, expect 3, provided : {}", - columns.len() - ), - } - ); + ensure_columns_n!(columns, 3); let lat_vec = &columns[0]; let lon_vec = &columns[1]; @@ -198,15 +234,7 @@ impl Function for H3LatLngToCellString { } fn eval(&self, _func_ctx: FunctionContext, columns: &[VectorRef]) -> Result { - ensure!( - columns.len() == 3, - InvalidFuncArgsSnafu { - err_msg: format!( - "The length of the args is not correct, expect 3, provided : {}", - columns.len() - ), - } - ); + ensure_columns_n!(columns, 3); let lat_vec = &columns[0]; let lon_vec = &columns[1]; @@ -262,15 +290,7 @@ impl Function for H3CellToString { } fn eval(&self, _func_ctx: FunctionContext, columns: &[VectorRef]) -> Result { - ensure!( - columns.len() == 1, - InvalidFuncArgsSnafu { - err_msg: format!( - "The length of the args is not correct, expect 1, provided : {}", - columns.len() - ), - } - ); + ensure_columns_n!(columns, 1); let cell_vec = &columns[0]; let size = cell_vec.len(); @@ -308,15 +328,7 @@ impl Function for H3StringToCell { } fn eval(&self, _func_ctx: FunctionContext, columns: &[VectorRef]) -> Result { - ensure!( - columns.len() == 1, - InvalidFuncArgsSnafu { - err_msg: format!( - "The length of the args is not correct, expect 1, provided : {}", - columns.len() - ), - } - ); + ensure_columns_n!(columns, 1); let string_vec = &columns[0]; let size = string_vec.len(); @@ -368,15 +380,7 @@ impl Function for H3CellCenterLatLng { } fn eval(&self, _func_ctx: FunctionContext, columns: &[VectorRef]) -> Result { - ensure!( - columns.len() == 1, - InvalidFuncArgsSnafu { - err_msg: format!( - "The length of the args is not correct, expect 1, provided : {}", - columns.len() - ), - } - ); + ensure_columns_n!(columns, 1); let cell_vec = &columns[0]; let size = cell_vec.len(); @@ -465,15 +469,7 @@ impl Function for H3CellBase { } fn eval(&self, _func_ctx: FunctionContext, columns: &[VectorRef]) -> Result { - ensure!( - columns.len() == 1, - InvalidFuncArgsSnafu { - err_msg: format!( - "The length of the args is not correct, expect 1, provided : {}", - columns.len() - ), - } - ); + ensure_columns_n!(columns, 1); let cell_vec = &columns[0]; let size = cell_vec.len(); @@ -509,15 +505,7 @@ impl Function for H3CellIsPentagon { } fn eval(&self, _func_ctx: FunctionContext, columns: &[VectorRef]) -> Result { - ensure!( - columns.len() == 1, - InvalidFuncArgsSnafu { - err_msg: format!( - "The length of the args is not correct, expect 1, provided : {}", - columns.len() - ), - } - ); + ensure_columns_n!(columns, 1); let cell_vec = &columns[0]; let size = cell_vec.len(); @@ -553,15 +541,7 @@ impl Function for H3CellCenterChild { } fn eval(&self, _func_ctx: FunctionContext, columns: &[VectorRef]) -> Result { - ensure!( - columns.len() == 2, - InvalidFuncArgsSnafu { - err_msg: format!( - "The length of the args is not correct, expect 2, provided : {}", - columns.len() - ), - } - ); + ensure_columns_n!(columns, 2); let cell_vec = &columns[0]; let res_vec = &columns[1]; @@ -601,15 +581,7 @@ impl Function for H3CellParent { } fn eval(&self, _func_ctx: FunctionContext, columns: &[VectorRef]) -> Result { - ensure!( - columns.len() == 2, - InvalidFuncArgsSnafu { - err_msg: format!( - "The length of the args is not correct, expect 2, provided : {}", - columns.len() - ), - } - ); + ensure_columns_n!(columns, 2); let cell_vec = &columns[0]; let res_vec = &columns[1]; @@ -649,15 +621,7 @@ impl Function for H3CellToChildren { } fn eval(&self, _func_ctx: FunctionContext, columns: &[VectorRef]) -> Result { - ensure!( - columns.len() == 2, - InvalidFuncArgsSnafu { - err_msg: format!( - "The length of the args is not correct, expect 2, provided : {}", - columns.len() - ), - } - ); + ensure_columns_n!(columns, 2); let cell_vec = &columns[0]; let res_vec = &columns[1]; @@ -706,15 +670,7 @@ impl Function for H3CellToChildrenSize { } fn eval(&self, _func_ctx: FunctionContext, columns: &[VectorRef]) -> Result { - ensure!( - columns.len() == 2, - InvalidFuncArgsSnafu { - err_msg: format!( - "The length of the args is not correct, expect 2, provided : {}", - columns.len() - ), - } - ); + ensure_columns_n!(columns, 2); let cell_vec = &columns[0]; let res_vec = &columns[1]; @@ -751,15 +707,7 @@ impl Function for H3CellToChildPos { } fn eval(&self, _func_ctx: FunctionContext, columns: &[VectorRef]) -> Result { - ensure!( - columns.len() == 2, - InvalidFuncArgsSnafu { - err_msg: format!( - "The length of the args is not correct, expect 2, provided : {}", - columns.len() - ), - } - ); + ensure_columns_n!(columns, 2); let cell_vec = &columns[0]; let res_vec = &columns[1]; @@ -808,15 +756,7 @@ impl Function for H3ChildPosToCell { } fn eval(&self, _func_ctx: FunctionContext, columns: &[VectorRef]) -> Result { - ensure!( - columns.len() == 3, - InvalidFuncArgsSnafu { - err_msg: format!( - "The length of the args is not correct, expect 3, provided : {}", - columns.len() - ), - } - ); + ensure_columns_n!(columns, 3); let pos_vec = &columns[0]; let cell_vec = &columns[1]; @@ -857,15 +797,7 @@ impl Function for H3GridDisk { } fn eval(&self, _func_ctx: FunctionContext, columns: &[VectorRef]) -> Result { - ensure!( - columns.len() == 2, - InvalidFuncArgsSnafu { - err_msg: format!( - "The length of the args is not correct, expect 2, provided : {}", - columns.len() - ), - } - ); + ensure_columns_n!(columns, 2); let cell_vec = &columns[0]; let k_vec = &columns[1]; @@ -918,15 +850,7 @@ impl Function for H3GridDiskDistances { } fn eval(&self, _func_ctx: FunctionContext, columns: &[VectorRef]) -> Result { - ensure!( - columns.len() == 2, - InvalidFuncArgsSnafu { - err_msg: format!( - "The length of the args is not correct, expect 2, provided : {}", - columns.len() - ), - } - ); + ensure_columns_n!(columns, 2); let cell_vec = &columns[0]; let k_vec = &columns[1]; @@ -976,15 +900,7 @@ impl Function for H3GridDistance { } fn eval(&self, _func_ctx: FunctionContext, columns: &[VectorRef]) -> Result { - ensure!( - columns.len() == 2, - InvalidFuncArgsSnafu { - err_msg: format!( - "The length of the args is not correct, expect 2, provided : {}", - columns.len() - ), - } - ); + ensure_columns_n!(columns, 2); let cell_this_vec = &columns[0]; let cell_that_vec = &columns[1]; @@ -1040,15 +956,7 @@ impl Function for H3GridPathCells { } fn eval(&self, _func_ctx: FunctionContext, columns: &[VectorRef]) -> Result { - ensure!( - columns.len() == 2, - InvalidFuncArgsSnafu { - err_msg: format!( - "The length of the args is not correct, expect 2, provided : {}", - columns.len() - ), - } - ); + ensure_columns_n!(columns, 2); let cell_this_vec = &columns[0]; let cell_that_vec = &columns[1]; From a286993f9430b08d010b7501ab6b193d011f8830 Mon Sep 17 00:00:00 2001 From: Ning Sun Date: Mon, 30 Sep 2024 17:12:24 -0700 Subject: [PATCH 7/7] refactor: fix lint warnings --- src/common/function/src/scalars/geo/h3.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/common/function/src/scalars/geo/h3.rs b/src/common/function/src/scalars/geo/h3.rs index 48b33623071..ddd86794087 100644 --- a/src/common/function/src/scalars/geo/h3.rs +++ b/src/common/function/src/scalars/geo/h3.rs @@ -33,20 +33,20 @@ use snafu::{ensure, ResultExt}; use crate::function::{Function, FunctionContext}; -const CELL_TYPES: Lazy> = Lazy::new(|| { +static CELL_TYPES: Lazy> = Lazy::new(|| { vec![ ConcreteDataType::int64_datatype(), ConcreteDataType::uint64_datatype(), ] }); -const COORDINATE_TYPES: Lazy> = Lazy::new(|| { +static COORDINATE_TYPES: Lazy> = Lazy::new(|| { vec![ ConcreteDataType::float32_datatype(), ConcreteDataType::float64_datatype(), ] }); -const RESOLUTION_TYPES: Lazy> = Lazy::new(|| { +static RESOLUTION_TYPES: Lazy> = Lazy::new(|| { vec![ ConcreteDataType::int8_datatype(), ConcreteDataType::int16_datatype(), @@ -58,7 +58,7 @@ const RESOLUTION_TYPES: Lazy> = Lazy::new(|| { ConcreteDataType::uint64_datatype(), ] }); -const DISTANCE_TYPES: Lazy> = Lazy::new(|| { +static DISTANCE_TYPES: Lazy> = Lazy::new(|| { vec![ ConcreteDataType::int8_datatype(), ConcreteDataType::int16_datatype(), @@ -71,7 +71,7 @@ const DISTANCE_TYPES: Lazy> = Lazy::new(|| { ] }); -const POSITION_TYPES: Lazy> = Lazy::new(|| { +static POSITION_TYPES: Lazy> = Lazy::new(|| { vec![ ConcreteDataType::int8_datatype(), ConcreteDataType::int16_datatype(),