Skip to content

Commit

Permalink
Merge pull request #5640 from leiysky/tuple
Browse files Browse the repository at this point in the history
feature(planner): Support tuple in new planner
  • Loading branch information
leiysky authored May 27, 2022
2 parents 801fc31 + 65f0a90 commit 6765e4c
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 19 deletions.
25 changes: 25 additions & 0 deletions query/src/sql/planner/semantic/type_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use common_exception::Result;
use common_functions::aggregates::AggregateFunctionFactory;
use common_functions::scalars::CastFunction;
use common_functions::scalars::FunctionFactory;
use common_functions::scalars::TupleFunction;

use crate::sessions::QueryContext;
use crate::sql::binder::Binder;
Expand Down Expand Up @@ -429,6 +430,8 @@ impl<'a> TypeChecker<'a> {
.await
}

Expr::Tuple { exprs, .. } => self.resolve_tuple(exprs).await,

_ => Err(ErrorCode::UnImplement(format!(
"Unsupported expr: {:?}",
expr
Expand Down Expand Up @@ -908,4 +911,26 @@ impl<'a> TypeChecker<'a> {
data_type,
))
}

async fn resolve_tuple(&mut self, exprs: &[Expr<'a>]) -> Result<(Scalar, DataTypeImpl)> {
let mut args = Vec::with_capacity(exprs.len());
let mut arg_types = Vec::with_capacity(exprs.len());
for expr in exprs {
let (arg, data_type) = self.resolve(expr, None).await?;
args.push(arg);
arg_types.push(data_type);
}
let arg_types_ref: Vec<&DataTypeImpl> = arg_types.iter().collect();
let tuple_func = TupleFunction::try_create_func("", &arg_types_ref)?;
Ok((
FunctionCall {
arguments: args,
func_name: "tuple".to_string(),
arg_types,
return_type: tuple_func.return_type(),
}
.into(),
tuple_func.return_type(),
))
}
}
2 changes: 1 addition & 1 deletion query/tests/it/servers/http/http_query_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ async fn test_query_log() -> Result<()> {
assert_eq!(status, StatusCode::OK, "{:?}", result);
assert!(result.error.is_none(), "{:?}", result);

let response = get_uri(&ep, &result.kill_uri.as_ref().unwrap()).await;
let response = get_uri(&ep, result.kill_uri.as_ref().unwrap()).await;
assert_eq!(response.status(), StatusCode::OK, "{:?}", result);

let sql = "select query_text, exception_code, exception_text, stack_trace from system.query_log where log_type=4";
Expand Down
20 changes: 4 additions & 16 deletions query/tests/it/sql/parsers/parser_select_table_at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::collections::HashMap;

use common_exception::Result;
use databend_query::sql::statements::AlterTableAction;
use databend_query::sql::statements::DfAlterTable;
use databend_query::sql::statements::DfCreateTable;
use databend_query::sql::statements::DfDescribeTable;
use databend_query::sql::statements::DfDropTable;
use databend_query::sql::statements::DfQueryStatement;
use databend_query::sql::statements::DfRenameTable;
use databend_query::sql::statements::DfShowCreateTable;
use databend_query::sql::statements::DfTruncateTable;
use databend_query::sql::*;
use sqlparser::ast::*;

Expand All @@ -37,12 +27,10 @@ fn select_table_at() -> Result<()> {
distinct: false,
from: vec![TableWithJoins {
relation: TableFactor::Table {
name: ObjectName {
0: vec![Ident {
value: "t".to_owned(),
quote_style: None,
}],
},
name: ObjectName(vec![Ident {
value: "t".to_owned(),
quote_style: None,
}]),
alias: None,
args: vec![],
with_hints: vec![],
Expand Down
4 changes: 2 additions & 2 deletions query/tests/it/storages/fuse/meta/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn snapshot_timestamp_monotonic_increase() {
let current = TableSnapshot::new(
uuid,
&prev.timestamp,
prev.prev_snapshot_id.clone(),
prev.prev_snapshot_id,
schema,
Default::default(),
vec![],
Expand All @@ -61,7 +61,7 @@ fn snapshot_timestamp_time_skew_tolerance() {
let current = TableSnapshot::new(
uuid,
&prev.timestamp,
prev.prev_snapshot_id.clone(),
prev.prev_snapshot_id,
schema,
Default::default(),
vec![],
Expand Down
6 changes: 6 additions & 0 deletions tests/suites/0_stateless/20+_others/20_0001_planner_v2.result
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,9 @@ BuildHashTable × 1 processor
4
0
2
====Tuple====
('field', 0)
('field', 1)
('field', 2)
('field', 3)
('field', 4)
3 changes: 3 additions & 0 deletions tests/suites/0_stateless/20+_others/20_0001_planner_v2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,7 @@ insert into t values ('foo');
select POSITION('o' IN t.a) from t;
drop table t;

select '====Tuple====';
select ('field', number) from numbers(5);

set enable_planner_v2 = 0;

0 comments on commit 6765e4c

Please sign in to comment.