diff --git a/rust/cubesql/cubesql/src/compile/mod.rs b/rust/cubesql/cubesql/src/compile/mod.rs index e0b4974a99166..2da928a683930 100644 --- a/rust/cubesql/cubesql/src/compile/mod.rs +++ b/rust/cubesql/cubesql/src/compile/mod.rs @@ -16333,4 +16333,19 @@ LIMIT {{ limit }}{% endif %}"#.to_string(), .sql; assert!(sql.contains(" IS NULL DESC, ")); } + + #[tokio::test] + async fn test_values_literal_table() -> Result<(), CubeError> { + insta::assert_snapshot!( + "values_literal_table", + execute_query( + r#"SELECT a AS a, b AS b FROM (VALUES (1, 2), (3, 4), (5, 6)) AS t(a, b)"# + .to_string(), + DatabaseProtocol::PostgreSQL + ) + .await? + ); + + Ok(()) + } } diff --git a/rust/cubesql/cubesql/src/compile/rewrite/converter.rs b/rust/cubesql/cubesql/src/compile/rewrite/converter.rs index 99d5057e706f3..5b028b24d37fd 100644 --- a/rust/cubesql/cubesql/src/compile/rewrite/converter.rs +++ b/rust/cubesql/cubesql/src/compile/rewrite/converter.rs @@ -26,7 +26,7 @@ use crate::{ SortExprAsc, SortExprNullsFirst, SubqueryTypes, TableScanFetch, TableScanProjection, TableScanSourceTableName, TableScanTableName, TableUDFExprFun, TimeDimensionDateRange, TimeDimensionGranularity, TimeDimensionName, TryCastExprDataType, UnionAlias, - WindowFunctionExprFun, WindowFunctionExprWindowFrame, WrappedSelectAlias, + ValuesValues, WindowFunctionExprFun, WindowFunctionExprWindowFrame, WrappedSelectAlias, WrappedSelectDistinct, WrappedSelectJoinJoinType, WrappedSelectLimit, WrappedSelectOffset, WrappedSelectPushToCube, WrappedSelectSelectType, WrappedSelectType, @@ -772,12 +772,13 @@ impl LogicalPlanToLanguageConverter { self.graph .add(LogicalPlanLanguage::Limit([skip, fetch, input])) } + LogicalPlan::Values(values) => { + let values = add_data_node!(self, values.values, ValuesValues); + self.graph.add(LogicalPlanLanguage::Values([values])) + } LogicalPlan::CreateExternalTable { .. } => { panic!("CreateExternalTable is not supported"); } - LogicalPlan::Values { .. } => { - panic!("Values is not supported"); - } LogicalPlan::Explain { .. } => { panic!("Explain is not supported"); } @@ -2283,6 +2284,11 @@ impl LanguageToLogicalPlanConverter { LogicalPlan::Distinct(Distinct { input }) } + LogicalPlanLanguage::Values(values) => { + let values = match_data_node!(node_by_id, values[0], ValuesValues); + + LogicalPlanBuilder::values(values)?.build()? + } x => panic!("Unexpected logical plan node: {:?}", x), }) } diff --git a/rust/cubesql/cubesql/src/compile/rewrite/mod.rs b/rust/cubesql/cubesql/src/compile/rewrite/mod.rs index 5473a4548f29a..c368ef8c1f4c1 100644 --- a/rust/cubesql/cubesql/src/compile/rewrite/mod.rs +++ b/rust/cubesql/cubesql/src/compile/rewrite/mod.rs @@ -157,6 +157,9 @@ crate::plan_to_language! { location: String, has_header: bool, }, + Values { + values: Vec>, + }, Extension { node: Arc, }, diff --git a/rust/cubesql/cubesql/src/compile/snapshots/cubesql__compile__tests__values_literal_table.snap b/rust/cubesql/cubesql/src/compile/snapshots/cubesql__compile__tests__values_literal_table.snap new file mode 100644 index 0000000000000..511bbe78035cf --- /dev/null +++ b/rust/cubesql/cubesql/src/compile/snapshots/cubesql__compile__tests__values_literal_table.snap @@ -0,0 +1,11 @@ +--- +source: cubesql/src/compile/mod.rs +expression: "execute_query(r#\"SELECT a AS a, b AS b FROM (VALUES (1, 2), (3, 4), (5, 6)) AS t(a, b)\"#.to_string(),\nDatabaseProtocol::PostgreSQL).await?" +--- ++---+---+ +| a | b | ++---+---+ +| 1 | 2 | +| 3 | 4 | +| 5 | 6 | ++---+---+