From 5d75f3e99712c7e168c2e3852fdba9eb9bd37518 Mon Sep 17 00:00:00 2001 From: Ning Sun Date: Sat, 5 Oct 2024 15:55:20 -0700 Subject: [PATCH] refactor: corrected to aggregation function --- src/common/function/src/scalars/aggregate.rs | 3 + .../function/src/scalars/aggregate/argmax.rs | 5 +- .../function/src/scalars/aggregate/argmin.rs | 5 +- .../function/src/scalars/aggregate/diff.rs | 4 +- .../function/src/scalars/aggregate/mean.rs | 4 +- .../function/src/scalars/aggregate/polyval.rs | 3 +- .../scalars/aggregate/scipy_stats_norm_cdf.rs | 4 +- .../scalars/aggregate/scipy_stats_norm_pdf.rs | 4 +- src/common/function/src/scalars/geo.rs | 5 +- .../function/src/scalars/geo/encoding.rs | 230 ++++++++++++------ src/common/macro/src/aggr_func.rs | 16 +- .../standalone/common/function/geo.result | 50 +--- .../cases/standalone/common/function/geo.sql | 20 +- .../information_schema/region_peers.result | 2 +- .../table_constraints.result | 4 - .../common/information_schema/tables.result | 1 - .../cases/standalone/common/partition.result | 2 - .../common/show/show_databases_tables.result | 1 - .../common/system/information_schema.result | 36 +-- .../common/system/pg_catalog.result | 48 ++-- .../common/tql/case_sensitive.result | 1 - .../standalone/common/view/create.result | 14 +- .../cases/standalone/common/view/view.result | 11 +- .../standalone/create/recover_created.result | 11 +- 24 files changed, 244 insertions(+), 240 deletions(-) diff --git a/src/common/function/src/scalars/aggregate.rs b/src/common/function/src/scalars/aggregate.rs index c6875a680c63..9ae846e1f142 100644 --- a/src/common/function/src/scalars/aggregate.rs +++ b/src/common/function/src/scalars/aggregate.rs @@ -31,6 +31,7 @@ pub use polyval::PolyvalAccumulatorCreator; pub use scipy_stats_norm_cdf::ScipyStatsNormCdfAccumulatorCreator; pub use scipy_stats_norm_pdf::ScipyStatsNormPdfAccumulatorCreator; +use super::geo::encoding::GeojsonPathEncodeFunctionCreator; use crate::function_registry::FunctionRegistry; /// A function creates `AggregateFunctionCreator`. @@ -91,5 +92,7 @@ impl AggregateFunctions { register_aggr_func!("argmin", 1, ArgminAccumulatorCreator); register_aggr_func!("scipystatsnormcdf", 2, ScipyStatsNormCdfAccumulatorCreator); register_aggr_func!("scipystatsnormpdf", 2, ScipyStatsNormPdfAccumulatorCreator); + + register_aggr_func!("geojson_encode_path", 3, GeojsonPathEncodeFunctionCreator); } } diff --git a/src/common/function/src/scalars/aggregate/argmax.rs b/src/common/function/src/scalars/aggregate/argmax.rs index c5c5264f1994..4749ff9a3a36 100644 --- a/src/common/function/src/scalars/aggregate/argmax.rs +++ b/src/common/function/src/scalars/aggregate/argmax.rs @@ -16,7 +16,10 @@ use std::cmp::Ordering; use std::sync::Arc; use common_macro::{as_aggr_func_creator, AggrFuncTypeStore}; -use common_query::error::{BadAccumulatorImplSnafu, CreateAccumulatorSnafu, Result}; +use common_query::error::{ + BadAccumulatorImplSnafu, CreateAccumulatorSnafu, InvalidInputStateSnafu, Result, +}; +use common_query::logical_plan::accumulator::AggrFuncTypeStore; use common_query::logical_plan::{Accumulator, AggregateFunctionCreator}; use common_query::prelude::*; use datatypes::prelude::*; diff --git a/src/common/function/src/scalars/aggregate/argmin.rs b/src/common/function/src/scalars/aggregate/argmin.rs index 7233f43b7708..fe891844604f 100644 --- a/src/common/function/src/scalars/aggregate/argmin.rs +++ b/src/common/function/src/scalars/aggregate/argmin.rs @@ -16,7 +16,10 @@ use std::cmp::Ordering; use std::sync::Arc; use common_macro::{as_aggr_func_creator, AggrFuncTypeStore}; -use common_query::error::{BadAccumulatorImplSnafu, CreateAccumulatorSnafu, Result}; +use common_query::error::{ + BadAccumulatorImplSnafu, CreateAccumulatorSnafu, InvalidInputStateSnafu, Result, +}; +use common_query::logical_plan::accumulator::AggrFuncTypeStore; use common_query::logical_plan::{Accumulator, AggregateFunctionCreator}; use common_query::prelude::*; use datatypes::prelude::*; diff --git a/src/common/function/src/scalars/aggregate/diff.rs b/src/common/function/src/scalars/aggregate/diff.rs index b83ed6d00496..25d1614e4b16 100644 --- a/src/common/function/src/scalars/aggregate/diff.rs +++ b/src/common/function/src/scalars/aggregate/diff.rs @@ -17,8 +17,10 @@ use std::sync::Arc; use common_macro::{as_aggr_func_creator, AggrFuncTypeStore}; use common_query::error::{ - CreateAccumulatorSnafu, DowncastVectorSnafu, FromScalarValueSnafu, Result, + CreateAccumulatorSnafu, DowncastVectorSnafu, FromScalarValueSnafu, InvalidInputStateSnafu, + Result, }; +use common_query::logical_plan::accumulator::AggrFuncTypeStore; use common_query::logical_plan::{Accumulator, AggregateFunctionCreator}; use common_query::prelude::*; use datatypes::prelude::*; diff --git a/src/common/function/src/scalars/aggregate/mean.rs b/src/common/function/src/scalars/aggregate/mean.rs index 3dc3e185351b..ed66c90bdb06 100644 --- a/src/common/function/src/scalars/aggregate/mean.rs +++ b/src/common/function/src/scalars/aggregate/mean.rs @@ -17,8 +17,10 @@ use std::sync::Arc; use common_macro::{as_aggr_func_creator, AggrFuncTypeStore}; use common_query::error::{ - BadAccumulatorImplSnafu, CreateAccumulatorSnafu, DowncastVectorSnafu, Result, + BadAccumulatorImplSnafu, CreateAccumulatorSnafu, DowncastVectorSnafu, InvalidInputStateSnafu, + Result, }; +use common_query::logical_plan::accumulator::AggrFuncTypeStore; use common_query::logical_plan::{Accumulator, AggregateFunctionCreator}; use common_query::prelude::*; use datatypes::prelude::*; diff --git a/src/common/function/src/scalars/aggregate/polyval.rs b/src/common/function/src/scalars/aggregate/polyval.rs index ae6ca101c45a..bc3986fd0e0b 100644 --- a/src/common/function/src/scalars/aggregate/polyval.rs +++ b/src/common/function/src/scalars/aggregate/polyval.rs @@ -18,8 +18,9 @@ use std::sync::Arc; use common_macro::{as_aggr_func_creator, AggrFuncTypeStore}; use common_query::error::{ self, BadAccumulatorImplSnafu, CreateAccumulatorSnafu, DowncastVectorSnafu, - FromScalarValueSnafu, InvalidInputColSnafu, Result, + FromScalarValueSnafu, InvalidInputColSnafu, InvalidInputStateSnafu, Result, }; +use common_query::logical_plan::accumulator::AggrFuncTypeStore; use common_query::logical_plan::{Accumulator, AggregateFunctionCreator}; use common_query::prelude::*; use datatypes::prelude::*; diff --git a/src/common/function/src/scalars/aggregate/scipy_stats_norm_cdf.rs b/src/common/function/src/scalars/aggregate/scipy_stats_norm_cdf.rs index e6c92225a682..09a9c820d866 100644 --- a/src/common/function/src/scalars/aggregate/scipy_stats_norm_cdf.rs +++ b/src/common/function/src/scalars/aggregate/scipy_stats_norm_cdf.rs @@ -17,8 +17,10 @@ use std::sync::Arc; use common_macro::{as_aggr_func_creator, AggrFuncTypeStore}; use common_query::error::{ self, BadAccumulatorImplSnafu, CreateAccumulatorSnafu, DowncastVectorSnafu, - FromScalarValueSnafu, GenerateFunctionSnafu, InvalidInputColSnafu, Result, + FromScalarValueSnafu, GenerateFunctionSnafu, InvalidInputColSnafu, InvalidInputStateSnafu, + Result, }; +use common_query::logical_plan::accumulator::AggrFuncTypeStore; use common_query::logical_plan::{Accumulator, AggregateFunctionCreator}; use common_query::prelude::*; use datatypes::prelude::*; diff --git a/src/common/function/src/scalars/aggregate/scipy_stats_norm_pdf.rs b/src/common/function/src/scalars/aggregate/scipy_stats_norm_pdf.rs index 3045ae8665dd..2d5025ea3ae5 100644 --- a/src/common/function/src/scalars/aggregate/scipy_stats_norm_pdf.rs +++ b/src/common/function/src/scalars/aggregate/scipy_stats_norm_pdf.rs @@ -17,8 +17,10 @@ use std::sync::Arc; use common_macro::{as_aggr_func_creator, AggrFuncTypeStore}; use common_query::error::{ self, BadAccumulatorImplSnafu, CreateAccumulatorSnafu, DowncastVectorSnafu, - FromScalarValueSnafu, GenerateFunctionSnafu, InvalidInputColSnafu, Result, + FromScalarValueSnafu, GenerateFunctionSnafu, InvalidInputColSnafu, InvalidInputStateSnafu, + Result, }; +use common_query::logical_plan::accumulator::AggrFuncTypeStore; use common_query::logical_plan::{Accumulator, AggregateFunctionCreator}; use common_query::prelude::*; use datatypes::prelude::*; diff --git a/src/common/function/src/scalars/geo.rs b/src/common/function/src/scalars/geo.rs index 5da7f5d7c24a..37b6c0704b06 100644 --- a/src/common/function/src/scalars/geo.rs +++ b/src/common/function/src/scalars/geo.rs @@ -13,7 +13,7 @@ // limitations under the License. use std::sync::Arc; -mod encoding; +pub(crate) mod encoding; mod geohash; mod h3; mod helpers; @@ -42,8 +42,5 @@ impl GeoFunctions { registry.register(Arc::new(h3::H3CellToString)); registry.register(Arc::new(h3::H3IsNeighbour)); registry.register(Arc::new(h3::H3StringToCell)); - - // encodings - registry.register(Arc::new(encoding::GeojsonPathEncode)); } } diff --git a/src/common/function/src/scalars/geo/encoding.rs b/src/common/function/src/scalars/geo/encoding.rs index 60a8fd459327..597824015cd3 100644 --- a/src/common/function/src/scalars/geo/encoding.rs +++ b/src/common/function/src/scalars/geo/encoding.rs @@ -12,108 +12,147 @@ // See the License for the specific language governing permissions and // limitations under the License. +use std::sync::Arc; + use common_error::ext::{BoxedError, PlainError}; use common_error::status_code::StatusCode; -use common_query::error::{self, InvalidFuncArgsSnafu, Result}; -use common_query::prelude::{Signature, TypeSignature}; +use common_macro::{as_aggr_func_creator, AggrFuncTypeStore}; +use common_query::error::{self, InvalidFuncArgsSnafu, InvalidInputStateSnafu, Result}; +use common_query::logical_plan::accumulator::AggrFuncTypeStore; +use common_query::logical_plan::{Accumulator, AggregateFunctionCreator}; +use common_query::prelude::AccumulatorCreatorFunction; use common_time::Timestamp; -use datafusion::logical_expr::Volatility; use datatypes::prelude::ConcreteDataType; -use datatypes::scalars::ScalarVectorBuilder; -use datatypes::vectors::{MutableVector, StringVectorBuilder, VectorRef}; -use derive_more::Display; -use once_cell::sync::Lazy; +use datatypes::value::{ListValue, Value}; +use datatypes::vectors::VectorRef; use snafu::{ensure, ResultExt}; use super::helpers::{ensure_columns_len, ensure_columns_n}; -use crate::function::{Function, FunctionContext}; - -static COORDINATE_TYPES: Lazy> = Lazy::new(|| { - vec![ - ConcreteDataType::float32_datatype(), - ConcreteDataType::float64_datatype(), - ] -}); - -fn build_sorted_path( - columns: &[VectorRef], -) -> Result, Option, Option)>> { - // this macro ensures column vectos has same size as well - ensure_columns_n!(columns, 3); - - let lat = &columns[0]; - let lng = &columns[1]; - let ts = &columns[2]; - - let size = lat.len(); - - let mut work_vec = Vec::with_capacity(size); - for idx in 0..size { - work_vec.push(( - lat.get(idx).as_f64_lossy(), - lng.get(idx).as_f64_lossy(), - ts.get(idx).as_timestamp(), - )); - } - // sort by timestamp, we treat null timestamp as 0 - work_vec.sort_unstable_by_key(|tuple| tuple.2.unwrap_or(Timestamp::new_second(0))); - Ok(work_vec) +/// Accumulator of lat, lng, timestmap tuples +#[derive(Debug)] +pub struct GeojsonPathAccumulator { + timestamp_type: ConcreteDataType, + lat: Vec>, + lng: Vec>, + timestamp: Vec>, } -/// This function accept rows of lat, lng and timestamp, sort with timestamp and -/// encoding them into a geojson-like path. -/// -/// Example: -/// -/// ```sql -/// SELECT geojson_encode(lat, lon, timestamp) FROM table; -/// ``` -/// -#[derive(Clone, Debug, Default, Display)] -#[display("{}", self.name())] -pub struct GeojsonPathEncode; +impl GeojsonPathAccumulator { + fn new(timestamp_type: ConcreteDataType) -> Self { + Self { + lat: Vec::default(), + lng: Vec::default(), + timestamp: Vec::default(), + timestamp_type, + } + } +} -impl Function for GeojsonPathEncode { - fn name(&self) -> &str { - "geojson_encode" +impl Accumulator for GeojsonPathAccumulator { + fn state(&self) -> Result> { + Ok(vec![ + Value::List(ListValue::new( + self.lat.iter().map(|i| Value::from(i.clone())).collect(), + ConcreteDataType::float64_datatype(), + )), + Value::List(ListValue::new( + self.lng.iter().map(|i| Value::from(i.clone())).collect(), + ConcreteDataType::float64_datatype(), + )), + Value::List(ListValue::new( + self.timestamp + .iter() + .map(|i| Value::from(i.clone())) + .collect(), + self.timestamp_type.clone(), + )), + ]) } - fn return_type(&self, _input_types: &[ConcreteDataType]) -> Result { - Ok(ConcreteDataType::string_datatype()) + fn update_batch(&mut self, columns: &[VectorRef]) -> Result<()> { + ensure_columns_n!(columns, 3); + + let lat = &columns[0]; + let lng = &columns[1]; + let ts = &columns[2]; + + let size = lat.len(); + + for idx in 0..size { + self.lat.push(lat.get(idx).as_f64_lossy()); + self.lng.push(lng.get(idx).as_f64_lossy()); + self.timestamp.push(ts.get(idx).as_timestamp()); + } + + Ok(()) } - fn signature(&self) -> Signature { - let mut signatures = Vec::new(); - let coord_types = COORDINATE_TYPES.as_slice(); - - let ts_types = ConcreteDataType::timestamps(); - for lat_type in coord_types { - for lng_type in coord_types { - for ts_type in &ts_types { - signatures.push(TypeSignature::Exact(vec![ - lat_type.clone(), - lng_type.clone(), - ts_type.clone(), - ])); + fn merge_batch(&mut self, states: &[VectorRef]) -> Result<()> { + ensure_columns_n!(states, 3); + + let lat_lists = &states[0]; + let lng_lists = &states[1]; + let ts_lists = &states[2]; + + let len = lat_lists.len(); + + for idx in 0..len { + if let Some(lat_list) = lat_lists + .get(idx) + .as_list() + .map_err(|e| BoxedError::new(e)) + .context(error::ExecuteSnafu)? + { + for v in lat_list.items() { + self.lat.push(v.as_f64_lossy()); + } + } + + if let Some(lng_list) = lng_lists + .get(idx) + .as_list() + .map_err(|e| BoxedError::new(e)) + .context(error::ExecuteSnafu)? + { + for v in lng_list.items() { + self.lng.push(v.as_f64_lossy()); + } + } + + if let Some(ts_list) = ts_lists + .get(idx) + .as_list() + .map_err(|e| BoxedError::new(e)) + .context(error::ExecuteSnafu)? + { + for v in ts_list.items() { + self.timestamp.push(v.as_timestamp()); } } } - Signature::one_of(signatures, Volatility::Stable) + Ok(()) } - fn eval(&self, _func_ctx: FunctionContext, columns: &[VectorRef]) -> Result { - let work_vec = build_sorted_path(columns)?; + fn evaluate(&self) -> Result { + let mut work_vec: Vec<(&Option, &Option, &Option)> = self + .lat + .iter() + .zip(self.lng.iter()) + .zip(self.timestamp.iter()) + .map(|((a, b), c)| (a, b, c)) + .collect(); - let mut results = StringVectorBuilder::with_capacity(1); + // sort by timestamp, we treat null timestamp as 0 + work_vec.sort_unstable_by_key(|tuple| tuple.2.unwrap_or_else(|| Timestamp::new_second(0))); let result = serde_json::to_string( &work_vec .into_iter() // note that we transform to lng,lat for geojson compatibility .map(|(lat, lng, _)| vec![lng, lat]) - .collect::>>>(), + .collect::>>>(), ) .map_err(|e| { BoxedError::new(PlainError::new( @@ -123,8 +162,47 @@ impl Function for GeojsonPathEncode { }) .context(error::ExecuteSnafu)?; - results.push(Some(&result)); + Ok(Value::String(result.into())) + } +} + +/// This function accept rows of lat, lng and timestamp, sort with timestamp and +/// encoding them into a geojson-like path. +/// +/// Example: +/// +/// ```sql +/// SELECT geojson_encode(lat, lon, timestamp) FROM table; +/// ``` +/// +#[as_aggr_func_creator] +#[derive(Debug, Default, AggrFuncTypeStore)] +pub struct GeojsonPathEncodeFunctionCreator {} + +impl AggregateFunctionCreator for GeojsonPathEncodeFunctionCreator { + fn creator(&self) -> AccumulatorCreatorFunction { + let creator: AccumulatorCreatorFunction = Arc::new(move |types: &[ConcreteDataType]| { + let ts_type = types[2].clone(); + Ok(Box::new(GeojsonPathAccumulator::new(ts_type))) + }); + + creator + } + + fn output_type(&self) -> Result { + Ok(ConcreteDataType::string_datatype()) + } + + fn state_types(&self) -> Result> { + let input_types = self.input_types()?; + ensure!(input_types.len() == 3, InvalidInputStateSnafu); + + let timestamp_type = input_types[2].clone(); - Ok(results.to_vector()) + Ok(vec![ + ConcreteDataType::list_datatype(ConcreteDataType::float64_datatype()), + ConcreteDataType::list_datatype(ConcreteDataType::float64_datatype()), + ConcreteDataType::list_datatype(timestamp_type), + ]) } } diff --git a/src/common/macro/src/aggr_func.rs b/src/common/macro/src/aggr_func.rs index 4c3ccccdeeb5..aee2954c4a30 100644 --- a/src/common/macro/src/aggr_func.rs +++ b/src/common/macro/src/aggr_func.rs @@ -21,23 +21,19 @@ use syn::{parse_macro_input, DeriveInput, ItemStruct}; pub(crate) fn impl_aggr_func_type_store(ast: &DeriveInput) -> TokenStream { let name = &ast.ident; let gen = quote! { - use common_query::logical_plan::accumulator::AggrFuncTypeStore; - use common_query::error::{InvalidInputStateSnafu, Error as QueryError}; - use datatypes::prelude::ConcreteDataType; - - impl AggrFuncTypeStore for #name { - fn input_types(&self) -> std::result::Result, QueryError> { + impl common_query::logical_plan::accumulator::AggrFuncTypeStore for #name { + fn input_types(&self) -> std::result::Result, common_query::error::Error> { let input_types = self.input_types.load(); - snafu::ensure!(input_types.is_some(), InvalidInputStateSnafu); + snafu::ensure!(input_types.is_some(), common_query::error::InvalidInputStateSnafu); Ok(input_types.as_ref().unwrap().as_ref().clone()) } - fn set_input_types(&self, input_types: Vec) -> std::result::Result<(), QueryError> { + fn set_input_types(&self, input_types: Vec) -> std::result::Result<(), common_query::error::Error> { let old = self.input_types.swap(Some(std::sync::Arc::new(input_types.clone()))); if let Some(old) = old { - snafu::ensure!(old.len() == input_types.len(), InvalidInputStateSnafu); + snafu::ensure!(old.len() == input_types.len(), common_query::error::InvalidInputStateSnafu); for (x, y) in old.iter().zip(input_types.iter()) { - snafu::ensure!(x == y, InvalidInputStateSnafu); + snafu::ensure!(x == y, common_query::error::InvalidInputStateSnafu); } } Ok(()) diff --git a/tests/cases/standalone/common/function/geo.result b/tests/cases/standalone/common/function/geo.result index 814b551ee4bc..f3a61ea76e77 100644 --- a/tests/cases/standalone/common/function/geo.result +++ b/tests/cases/standalone/common/function/geo.result @@ -236,15 +236,15 @@ SELECT geohash_neighbours(37.76938, -122.3889, 11); | [9q8yygxnefv, 9q8yygxnefu, 9q8yygxnefs, 9q8yygxnefk, 9q8yygxnefm, 9q8yygxnefq, 9q8yygxnefw, 9q8yygxnefy] | +----------------------------------------------------------------------------------------------------------+ -SELECT geojson_encode(37.76938, -122.3889, 1728083375::TimestampSecond); +SELECT geojson_encode_path(37.76938, -122.3889, 1728083375::TimestampSecond); -+--------------------------------------------------------------------------------------------------------------------+ -| geojson_encode(Float64(37.76938),Float64(-122.3889),arrow_cast(Int64(1728083375),Utf8("Timestamp(Second, None)"))) | -+--------------------------------------------------------------------------------------------------------------------+ -| [[-122.3889,37.76938]] | -+--------------------------------------------------------------------------------------------------------------------+ ++-------------------------------------------------------------------------------------------------------------------------+ +| geojson_encode_path(Float64(37.76938),Float64(-122.3889),arrow_cast(Int64(1728083375),Utf8("Timestamp(Second, None)"))) | ++-------------------------------------------------------------------------------------------------------------------------+ +| [[-122.3889,37.76938]] | ++-------------------------------------------------------------------------------------------------------------------------+ -SELECT geojson_encode(lat, lon, ts) +SELECT geojson_encode_path(lat, lon, ts) FROM( SELECT 37.76938 AS lat, -122.3889 AS lon, 1728083375::TimestampSecond AS ts UNION ALL @@ -255,35 +255,9 @@ FROM( SELECT 37.77001 AS lat, -122.3888 AS lon, 1728083372::TimestampSecond AS ts ); -+----------------------------+ -| geojson_encode(lat,lon,ts) | -+----------------------------+ -| [[-122.3839,37.76928]] | -| [[-122.3888,37.77001]] | -| [[-122.382,37.7693]] | -| [[-122.3889,37.76938]] | -+----------------------------+ - -CREATE TABLE caltrack ( - ts TIMESTAMPSECOND TIME INDEX, - lat FLOAT32, - lon FLOAT32, - recorder STRING, - PRIMARY KEY (recorder) -); - -Affected Rows: 0 - -INSERT INTO caltrack(ts, lat, lon, recorder) VALUES - (1728083375, 37.76938, -122.3889, 'osmand'), - (1728083373, 37.76928, -122.3839, 'osmand'), - (1728083379, 37.76930, -122.3820, 'osmand'), - (1728083372, 37.77001, -122.3888, 'osmand'); - -Affected Rows: 4 - -SELECT geojson_encode(lat, lon, ts) FROM caltrack WHERE recorder = 'osmand'; - -Error: 3001(EngineExecuteQuery), Internal error: UDF returned a different number of rows than expected. Expected: 4, Got: 1. -This was likely caused by a bug in DataFusion's code and we would welcome that you file an bug report in our issue tracker ++-------------------------------------------------------------------------------------+ +| geojson_encode_path(lat,lon,ts) | ++-------------------------------------------------------------------------------------+ +| [[-122.3888,37.77001],[-122.3839,37.76928],[-122.3889,37.76938],[-122.382,37.7693]] | ++-------------------------------------------------------------------------------------+ diff --git a/tests/cases/standalone/common/function/geo.sql b/tests/cases/standalone/common/function/geo.sql index b20623c3cb32..0103a2c6eb97 100644 --- a/tests/cases/standalone/common/function/geo.sql +++ b/tests/cases/standalone/common/function/geo.sql @@ -67,9 +67,9 @@ SELECT geohash(37.76938, -122.3889, 11::UInt64); SELECT geohash_neighbours(37.76938, -122.3889, 11); -SELECT geojson_encode(37.76938, -122.3889, 1728083375::TimestampSecond); +SELECT geojson_encode_path(37.76938, -122.3889, 1728083375::TimestampSecond); -SELECT geojson_encode(lat, lon, ts) +SELECT geojson_encode_path(lat, lon, ts) FROM( SELECT 37.76938 AS lat, -122.3889 AS lon, 1728083375::TimestampSecond AS ts UNION ALL @@ -79,19 +79,3 @@ FROM( UNION ALL SELECT 37.77001 AS lat, -122.3888 AS lon, 1728083372::TimestampSecond AS ts ); - -CREATE TABLE caltrack ( - ts TIMESTAMPSECOND TIME INDEX, - lat FLOAT32, - lon FLOAT32, - recorder STRING, - PRIMARY KEY (recorder) -); - -INSERT INTO caltrack(ts, lat, lon, recorder) VALUES - (1728083375, 37.76938, -122.3889, 'osmand'), - (1728083373, 37.76928, -122.3839, 'osmand'), - (1728083379, 37.76930, -122.3820, 'osmand'), - (1728083372, 37.77001, -122.3888, 'osmand'); - -SELECT geojson_encode(lat, lon, ts) FROM caltrack WHERE recorder = 'osmand'; diff --git a/tests/cases/standalone/common/information_schema/region_peers.result b/tests/cases/standalone/common/information_schema/region_peers.result index bd2cf51bb70a..0c7919e5dd4d 100644 --- a/tests/cases/standalone/common/information_schema/region_peers.result +++ b/tests/cases/standalone/common/information_schema/region_peers.result @@ -44,7 +44,7 @@ SELECT COUNT(distinct region_id) FROM region_peers; +----------------------------------------+ | COUNT(DISTINCT region_peers.region_id) | +----------------------------------------+ -| 7 | +| 6 | +----------------------------------------+ use public; diff --git a/tests/cases/standalone/common/information_schema/table_constraints.result b/tests/cases/standalone/common/information_schema/table_constraints.result index ff357916a007..573336458771 100644 --- a/tests/cases/standalone/common/information_schema/table_constraints.result +++ b/tests/cases/standalone/common/information_schema/table_constraints.result @@ -22,8 +22,6 @@ SELECT * FROM TABLE_CONSTRAINTS ORDER BY TABLE_NAME, CONSTRAINT_NAME; +--------------------+-------------------+-----------------+--------------+------------+-----------------+----------+ | constraint_catalog | constraint_schema | constraint_name | table_schema | table_name | constraint_type | enforced | +--------------------+-------------------+-----------------+--------------+------------+-----------------+----------+ -| def | public | PRIMARY | public | caltrack | PRIMARY KEY | YES | -| def | public | TIME INDEX | public | caltrack | TIME INDEX | YES | | def | public | PRIMARY | public | numbers | PRIMARY KEY | YES | +--------------------+-------------------+-----------------+--------------+------------+-----------------+----------+ @@ -44,8 +42,6 @@ SELECT * FROM TABLE_CONSTRAINTS ORDER BY TABLE_NAME, CONSTRAINT_NAME; +--------------------+-------------------+-----------------+--------------+------------+-----------------+----------+ | constraint_catalog | constraint_schema | constraint_name | table_schema | table_name | constraint_type | enforced | +--------------------+-------------------+-----------------+--------------+------------+-----------------+----------+ -| def | public | PRIMARY | public | caltrack | PRIMARY KEY | YES | -| def | public | TIME INDEX | public | caltrack | TIME INDEX | YES | | def | public | PRIMARY | public | numbers | PRIMARY KEY | YES | | def | public | PRIMARY | public | test | PRIMARY KEY | YES | | def | public | TIME INDEX | public | test | TIME INDEX | YES | diff --git a/tests/cases/standalone/common/information_schema/tables.result b/tests/cases/standalone/common/information_schema/tables.result index c48628449f9e..93a93a9c9805 100644 --- a/tests/cases/standalone/common/information_schema/tables.result +++ b/tests/cases/standalone/common/information_schema/tables.result @@ -30,7 +30,6 @@ select table_catalog, table_schema, table_name from information_schema.tables wh | greptime | abc | t | | greptime | abcde | t | | greptime | public | numbers | -| greptime | public | caltrack | +---------------+--------------+------------+ use public; diff --git a/tests/cases/standalone/common/partition.result b/tests/cases/standalone/common/partition.result index a70fb1c3bf98..cdf0f51be57c 100644 --- a/tests/cases/standalone/common/partition.result +++ b/tests/cases/standalone/common/partition.result @@ -32,7 +32,6 @@ SELECT region_id, peer_id, is_leader, status FROM information_schema.region_peer | REGION_ID | PEER_ID | Yes | ALIVE | | REGION_ID | PEER_ID | Yes | ALIVE | | REGION_ID | PEER_ID | Yes | ALIVE | -| REGION_ID | PEER_ID | Yes | ALIVE | +---------------+---------+-----------+--------+ INSERT INTO my_table VALUES @@ -138,7 +137,6 @@ SELECT region_id, peer_id, is_leader, status FROM information_schema.region_peer | region_id | peer_id | is_leader | status | +---------------+---------+-----------+--------+ | REGION_ID | PEER_ID | Yes | ALIVE | -| REGION_ID | PEER_ID | Yes | ALIVE | +---------------+---------+-----------+--------+ INSERT INTO my_table VALUES diff --git a/tests/cases/standalone/common/show/show_databases_tables.result b/tests/cases/standalone/common/show/show_databases_tables.result index 75f8173165c6..6dc267b61bac 100644 --- a/tests/cases/standalone/common/show/show_databases_tables.result +++ b/tests/cases/standalone/common/show/show_databases_tables.result @@ -179,7 +179,6 @@ SHOW TABLE STATUS from public; +++++++++++++++++++ |Name|Engine|Version|Row_format|Rows|Avg_row_length|Data_length|Max_data_length|Index_length|Data_free|Auto_increment|Create_time|Update_time|Check_time|Collation|Checksum|Create_options|Comment| +++++++++++++++++++ -|caltrack|mito|11|Fixed|0|0|0|0|0|0|0|DATETIME|||utf8_bin|0||| |numbers|test_engine|11|Fixed|0|0|0|0|0|0|0|DATETIME|||utf8_bin|0||| +++++++++++++++++++ diff --git a/tests/cases/standalone/common/system/information_schema.result b/tests/cases/standalone/common/system/information_schema.result index 36c69be7ec83..4264bd8df66e 100644 --- a/tests/cases/standalone/common/system/information_schema.result +++ b/tests/cases/standalone/common/system/information_schema.result @@ -47,7 +47,6 @@ order by table_schema, table_name; |greptime|information_schema|tables|LOCALTEMPORARY|3|0|0|0|0|0||11|Fixed|0|0|0|DATETIME|||utf8_bin|0|||Y| |greptime|information_schema|triggers|LOCALTEMPORARY|24|0|0|0|0|0||11|Fixed|0|0|0|DATETIME|||utf8_bin|0|||Y| |greptime|information_schema|views|LOCALTEMPORARY|32|0|0|0|0|0||11|Fixed|0|0|0|DATETIME|||utf8_bin|0|||Y| -|greptime|public|caltrack|BASETABLE|1190|0|0|0|0|0|mito|11|Fixed|0|0|0|DATETIME|||utf8_bin|0|||N| |greptime|public|numbers|LOCALTEMPORARY|2|0|0|0|0|0|test_engine|11|Fixed|0|0|0|DATETIME|||utf8_bin|0|||Y| +++++++++++++++++++++++++ @@ -427,10 +426,6 @@ select * from information_schema.columns order by table_schema, table_name, colu | greptime | information_schema | views | table_name | 3 | 2147483647 | 2147483647 | | | | utf8 | utf8_bin | | | select,insert | | String | string | FIELD | | No | string | | | | greptime | information_schema | views | table_schema | 2 | 2147483647 | 2147483647 | | | | utf8 | utf8_bin | | | select,insert | | String | string | FIELD | | No | string | | | | greptime | information_schema | views | view_definition | 4 | 2147483647 | 2147483647 | | | | utf8 | utf8_bin | | | select,insert | | String | string | FIELD | | No | string | | | -| greptime | public | caltrack | lat | 2 | | | 12 | | | | | | | select,insert | | Float32 | float | FIELD | | Yes | float | | | -| greptime | public | caltrack | lon | 3 | | | 12 | | | | | | | select,insert | | Float32 | float | FIELD | | Yes | float | | | -| greptime | public | caltrack | recorder | 4 | 2147483647 | 2147483647 | | | | utf8 | utf8_bin | PRI | | select,insert | | String | string | TAG | | Yes | string | | | -| greptime | public | caltrack | ts | 1 | | | | | 0 | | | TIME INDEX | | select,insert | | TimestampSecond | timestamp(0) | TIMESTAMP | | No | timestamp(0) | | | | greptime | public | numbers | number | 1 | | | 10 | 0 | | | | PRI | | select,insert | | UInt32 | int unsigned | TAG | | No | int unsigned | | | +---------------+--------------------+---------------------------------------+-----------------------------------+------------------+--------------------------+------------------------+-------------------+---------------+--------------------+--------------------+----------------+------------+-------+---------------+-----------------------+----------------------+-----------------+---------------+----------------+-------------+-----------------+----------------+--------+ @@ -473,7 +468,6 @@ order by table_name; +------------+ | table_name | +------------+ -| caltrack | | foo | | numbers | +------------+ @@ -497,7 +491,6 @@ order by table_name; +------------+ | table_name | +------------+ -| caltrack | | numbers | +------------+ @@ -542,10 +535,6 @@ order by table_schema, table_name, column_name; | table_catalog | table_schema | table_name | column_name | data_type | semantic_type | +---------------+--------------+------------+-------------+--------------+---------------+ | greptime | my_db | foo | ts | timestamp(3) | TIMESTAMP | -| greptime | public | caltrack | lat | float | FIELD | -| greptime | public | caltrack | lon | float | FIELD | -| greptime | public | caltrack | recorder | string | TAG | -| greptime | public | caltrack | ts | timestamp(0) | TIMESTAMP | | greptime | public | numbers | number | int unsigned | TAG | +---------------+--------------+------------+-------------+--------------+---------------+ @@ -564,11 +553,8 @@ Affected Rows: 0 -- test query filter for key_column_usage -- select * from KEY_COLUMN_USAGE where CONSTRAINT_NAME = 'TIME INDEX'; -+--------------------+-------------------+-----------------+---------------+--------------------+--------------+------------+-------------+------------------+-------------------------------+-------------------------+-----------------------+------------------------+ -| constraint_catalog | constraint_schema | constraint_name | table_catalog | real_table_catalog | table_schema | table_name | column_name | ordinal_position | position_in_unique_constraint | referenced_table_schema | referenced_table_name | referenced_column_name | -+--------------------+-------------------+-----------------+---------------+--------------------+--------------+------------+-------------+------------------+-------------------------------+-------------------------+-----------------------+------------------------+ -| def | public | TIME INDEX | def | greptime | public | caltrack | ts | 1 | | | | | -+--------------------+-------------------+-----------------+---------------+--------------------+--------------+------------+-------------+------------------+-------------------------------+-------------------------+-----------------------+------------------------+ +++ +++ select * from KEY_COLUMN_USAGE where CONSTRAINT_NAME != 'TIME INDEX'; @@ -576,16 +562,12 @@ select * from KEY_COLUMN_USAGE where CONSTRAINT_NAME != 'TIME INDEX'; | constraint_catalog | constraint_schema | constraint_name | table_catalog | real_table_catalog | table_schema | table_name | column_name | ordinal_position | position_in_unique_constraint | referenced_table_schema | referenced_table_name | referenced_column_name | +--------------------+-------------------+-----------------+---------------+--------------------+--------------+------------+-------------+------------------+-------------------------------+-------------------------+-----------------------+------------------------+ | def | public | PRIMARY | def | greptime | public | numbers | number | 1 | | | | | -| def | public | PRIMARY | def | greptime | public | caltrack | recorder | 1 | | | | | +--------------------+-------------------+-----------------+---------------+--------------------+--------------+------------+-------------+------------------+-------------------------------+-------------------------+-----------------------+------------------------+ select * from KEY_COLUMN_USAGE where CONSTRAINT_NAME LIKE '%INDEX'; -+--------------------+-------------------+-----------------+---------------+--------------------+--------------+------------+-------------+------------------+-------------------------------+-------------------------+-----------------------+------------------------+ -| constraint_catalog | constraint_schema | constraint_name | table_catalog | real_table_catalog | table_schema | table_name | column_name | ordinal_position | position_in_unique_constraint | referenced_table_schema | referenced_table_name | referenced_column_name | -+--------------------+-------------------+-----------------+---------------+--------------------+--------------+------------+-------------+------------------+-------------------------------+-------------------------+-----------------------+------------------------+ -| def | public | TIME INDEX | def | greptime | public | caltrack | ts | 1 | | | | | -+--------------------+-------------------+-----------------+---------------+--------------------+--------------+------------+-------------+------------------+-------------------------------+-------------------------+-----------------------+------------------------+ +++ +++ select * from KEY_COLUMN_USAGE where CONSTRAINT_NAME NOT LIKE '%INDEX'; @@ -593,16 +575,12 @@ select * from KEY_COLUMN_USAGE where CONSTRAINT_NAME NOT LIKE '%INDEX'; | constraint_catalog | constraint_schema | constraint_name | table_catalog | real_table_catalog | table_schema | table_name | column_name | ordinal_position | position_in_unique_constraint | referenced_table_schema | referenced_table_name | referenced_column_name | +--------------------+-------------------+-----------------+---------------+--------------------+--------------+------------+-------------+------------------+-------------------------------+-------------------------+-----------------------+------------------------+ | def | public | PRIMARY | def | greptime | public | numbers | number | 1 | | | | | -| def | public | PRIMARY | def | greptime | public | caltrack | recorder | 1 | | | | | +--------------------+-------------------+-----------------+---------------+--------------------+--------------+------------+-------------+------------------+-------------------------------+-------------------------+-----------------------+------------------------+ select * from KEY_COLUMN_USAGE where CONSTRAINT_NAME == 'TIME INDEX' AND CONSTRAINT_SCHEMA != 'my_db'; -+--------------------+-------------------+-----------------+---------------+--------------------+--------------+------------+-------------+------------------+-------------------------------+-------------------------+-----------------------+------------------------+ -| constraint_catalog | constraint_schema | constraint_name | table_catalog | real_table_catalog | table_schema | table_name | column_name | ordinal_position | position_in_unique_constraint | referenced_table_schema | referenced_table_name | referenced_column_name | -+--------------------+-------------------+-----------------+---------------+--------------------+--------------+------------+-------------+------------------+-------------------------------+-------------------------+-----------------------+------------------------+ -| def | public | TIME INDEX | def | greptime | public | caltrack | ts | 1 | | | | | -+--------------------+-------------------+-----------------+---------------+--------------------+--------------+------------+-------------+------------------+-------------------------------+-------------------------+-----------------------+------------------------+ +++ +++ -- schemata -- desc table schemata; @@ -683,8 +661,6 @@ select * from key_column_usage; | constraint_catalog | constraint_schema | constraint_name | table_catalog | real_table_catalog | table_schema | table_name | column_name | ordinal_position | position_in_unique_constraint | referenced_table_schema | referenced_table_name | referenced_column_name | +--------------------+-------------------+-----------------+---------------+--------------------+--------------+------------+-------------+------------------+-------------------------------+-------------------------+-----------------------+------------------------+ | def | public | PRIMARY | def | greptime | public | numbers | number | 1 | | | | | -| def | public | TIME INDEX | def | greptime | public | caltrack | ts | 1 | | | | | -| def | public | PRIMARY | def | greptime | public | caltrack | recorder | 1 | | | | | +--------------------+-------------------+-----------------+---------------+--------------------+--------------+------------+-------------+------------------+-------------------------------+-------------------------+-----------------------+------------------------+ -- tables not implemented diff --git a/tests/cases/standalone/common/system/pg_catalog.result b/tests/cases/standalone/common/system/pg_catalog.result index acd85b3db432..4e3e217b2e9b 100644 --- a/tests/cases/standalone/common/system/pg_catalog.result +++ b/tests/cases/standalone/common/system/pg_catalog.result @@ -59,12 +59,11 @@ WHERE c.relkind IN ('r','p','v','m','S','f','') AND pg_catalog.pg_table_is_visible(c.oid) ORDER BY 1,2; -+--------+----------+-------+-------+ -| Schema | Name | Type | Owner | -+--------+----------+-------+-------+ -| public | caltrack | table | | -| public | numbers | table | | -+--------+----------+-------+-------+ ++--------+---------+-------+-------+ +| Schema | Name | Type | Owner | ++--------+---------+-------+-------+ +| public | numbers | table | | ++--------+---------+-------+-------+ -- \dt -- SQLNESS PROTOCOL POSTGRES @@ -81,12 +80,11 @@ WHERE c.relkind IN ('r','p','') AND pg_catalog.pg_table_is_visible(c.oid) ORDER BY 1,2; -+--------+----------+-------+-------+ -| Schema | Name | Type | Owner | -+--------+----------+-------+-------+ -| public | caltrack | table | | -| public | numbers | table | | -+--------+----------+-------+-------+ ++--------+---------+-------+-------+ +| Schema | Name | Type | Owner | ++--------+---------+-------+-------+ +| public | numbers | table | | ++--------+---------+-------+-------+ -- make sure oid of namespace keep stable -- SQLNESS PROTOCOL POSTGRES @@ -150,13 +148,12 @@ WHERE c.relkind IN ('r','p','') AND pg_catalog.pg_table_is_visible(c.oid) ORDER BY 1,2; -+--------+----------+-------+-------+ -| Schema | Name | Type | Owner | -+--------+----------+-------+-------+ -| my_db | foo | table | | -| public | caltrack | table | | -| public | numbers | table | | -+--------+----------+-------+-------+ ++--------+---------+-------+-------+ +| Schema | Name | Type | Owner | ++--------+---------+-------+-------+ +| my_db | foo | table | | +| public | numbers | table | | ++--------+---------+-------+-------+ -- show tables in `my_db`, `public` -- SQLNESS PROTOCOL POSTGRES @@ -169,13 +166,12 @@ where relnamespace in ( ) order by relname; -+----------+ -| relname | -+----------+ -| caltrack | -| foo | -| numbers | -+----------+ ++---------+ +| relname | ++---------+ +| foo | +| numbers | ++---------+ -- SQLNESS PROTOCOL POSTGRES select relname diff --git a/tests/cases/standalone/common/tql/case_sensitive.result b/tests/cases/standalone/common/tql/case_sensitive.result index f9deea6b517e..e4e305a27e6c 100644 --- a/tests/cases/standalone/common/tql/case_sensitive.result +++ b/tests/cases/standalone/common/tql/case_sensitive.result @@ -31,7 +31,6 @@ select table_name from information_schema.tables where table_type = 'BASE TABLE' +--------------+ | table_name | +--------------+ -| caltrack | | MemAvailable | | MemTotal | +--------------+ diff --git a/tests/cases/standalone/common/view/create.result b/tests/cases/standalone/common/view/create.result index 734c9cdce82c..06d892d1896f 100644 --- a/tests/cases/standalone/common/view/create.result +++ b/tests/cases/standalone/common/view/create.result @@ -48,7 +48,6 @@ SHOW TABLES; +------------+ | Tables | +------------+ -| caltrack | | numbers | | test_table | | test_view | @@ -59,7 +58,6 @@ SHOW FULL TABLES; +------------+-----------------+ | Tables | Table_type | +------------+-----------------+ -| caltrack | BASE TABLE | | numbers | LOCAL TEMPORARY | | test_table | BASE TABLE | | test_view | VIEW | @@ -90,7 +88,6 @@ SELECT * FROM INFORMATION_SCHEMA.TABLES ORDER BY TABLE_NAME, TABLE_TYPE; |table_catalog|table_schema|table_name|table_type|table_id|data_length|max_data_length|index_length|max_index_length|avg_row_length|engine|version|row_format|table_rows|data_free|auto_increment|create_time|update_time|check_time|table_collation|checksum|create_options|table_comment|temporary| +++++++++++++++++++++++++ |greptime|information_schema|build_info|LOCALTEMPORARY|ID|ID|ID|ID|ID|ID||ID|Fixed|ID|ID|ID|DATETIME|||utf8_bin|ID|||Y| -|greptime|public|caltrack|BASETABLE|ID|ID|ID|ID|ID|ID|mito|ID|Fixed|ID|ID|ID|DATETIME|||utf8_bin|ID|||N| |greptime|information_schema|character_sets|LOCALTEMPORARY|ID|ID|ID|ID|ID|ID||ID|Fixed|ID|ID|ID|DATETIME|||utf8_bin|ID|||Y| |greptime|information_schema|check_constraints|LOCALTEMPORARY|ID|ID|ID|ID|ID|ID||ID|Fixed|ID|ID|ID|DATETIME|||utf8_bin|ID|||Y| |greptime|information_schema|cluster_info|LOCALTEMPORARY|ID|ID|ID|ID|ID|ID||ID|Fixed|ID|ID|ID|DATETIME|||utf8_bin|ID|||Y| @@ -183,12 +180,11 @@ Error: 4001(TableNotFound), Failed to plan SQL: Table not found: greptime.public SHOW TABLES; -+----------+ -| Tables | -+----------+ -| caltrack | -| numbers | -+----------+ ++---------+ +| Tables | ++---------+ +| numbers | ++---------+ -- psql: \dv SELECT n.nspname as "Schema", diff --git a/tests/cases/standalone/common/view/view.result b/tests/cases/standalone/common/view/view.result index 2b2c3bf39748..6e1220211496 100644 --- a/tests/cases/standalone/common/view/view.result +++ b/tests/cases/standalone/common/view/view.result @@ -83,12 +83,11 @@ Affected Rows: 0 SHOW TABLES; -+----------+ -| Tables | -+----------+ -| caltrack | -| numbers | -+----------+ ++---------+ +| Tables | ++---------+ +| numbers | ++---------+ SHOW VIEWS; diff --git a/tests/cases/standalone/create/recover_created.result b/tests/cases/standalone/create/recover_created.result index 2f489729085f..c384a7888a2f 100644 --- a/tests/cases/standalone/create/recover_created.result +++ b/tests/cases/standalone/create/recover_created.result @@ -17,12 +17,11 @@ Affected Rows: 0 -- SQLNESS ARG restart=true show tables; -+----------+ -| Tables | -+----------+ -| caltrack | -| numbers | -+----------+ ++---------+ +| Tables | ++---------+ +| numbers | ++---------+ create table t3 (c timestamp time index);