Skip to content

Commit 786b1f1

Browse files
committed
feat(cubesql): Basic VALUES support in rewrite engine
1 parent fd4ccff commit 786b1f1

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

rust/cubesql/cubesql/src/compile/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16333,4 +16333,19 @@ LIMIT {{ limit }}{% endif %}"#.to_string(),
1633316333
.sql;
1633416334
assert!(sql.contains(" IS NULL DESC, "));
1633516335
}
16336+
16337+
#[tokio::test]
16338+
async fn test_values_literal_table() -> Result<(), CubeError> {
16339+
insta::assert_snapshot!(
16340+
"values_literal_table",
16341+
execute_query(
16342+
r#"SELECT a AS a, b AS b FROM (VALUES (1, 2), (3, 4), (5, 6)) AS t(a, b)"#
16343+
.to_string(),
16344+
DatabaseProtocol::PostgreSQL
16345+
)
16346+
.await?
16347+
);
16348+
16349+
Ok(())
16350+
}
1633616351
}

rust/cubesql/cubesql/src/compile/rewrite/converter.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::{
2626
SortExprAsc, SortExprNullsFirst, SubqueryTypes, TableScanFetch, TableScanProjection,
2727
TableScanSourceTableName, TableScanTableName, TableUDFExprFun, TimeDimensionDateRange,
2828
TimeDimensionGranularity, TimeDimensionName, TryCastExprDataType, UnionAlias,
29-
WindowFunctionExprFun, WindowFunctionExprWindowFrame, WrappedSelectAlias,
29+
ValuesValues, WindowFunctionExprFun, WindowFunctionExprWindowFrame, WrappedSelectAlias,
3030
WrappedSelectDistinct, WrappedSelectJoinJoinType, WrappedSelectLimit,
3131
WrappedSelectOffset, WrappedSelectPushToCube, WrappedSelectSelectType,
3232
WrappedSelectType,
@@ -772,12 +772,13 @@ impl LogicalPlanToLanguageConverter {
772772
self.graph
773773
.add(LogicalPlanLanguage::Limit([skip, fetch, input]))
774774
}
775+
LogicalPlan::Values(values) => {
776+
let values = add_data_node!(self, values.values, ValuesValues);
777+
self.graph.add(LogicalPlanLanguage::Values([values]))
778+
}
775779
LogicalPlan::CreateExternalTable { .. } => {
776780
panic!("CreateExternalTable is not supported");
777781
}
778-
LogicalPlan::Values { .. } => {
779-
panic!("Values is not supported");
780-
}
781782
LogicalPlan::Explain { .. } => {
782783
panic!("Explain is not supported");
783784
}
@@ -2283,6 +2284,11 @@ impl LanguageToLogicalPlanConverter {
22832284

22842285
LogicalPlan::Distinct(Distinct { input })
22852286
}
2287+
LogicalPlanLanguage::Values(values) => {
2288+
let values = match_data_node!(node_by_id, values[0], ValuesValues);
2289+
2290+
LogicalPlanBuilder::values(values)?.build()?
2291+
}
22862292
x => panic!("Unexpected logical plan node: {:?}", x),
22872293
})
22882294
}

rust/cubesql/cubesql/src/compile/rewrite/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ crate::plan_to_language! {
157157
location: String,
158158
has_header: bool,
159159
},
160+
Values {
161+
values: Vec<Vec<Expr>>,
162+
},
160163
Extension {
161164
node: Arc<LogicalPlan>,
162165
},
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
source: cubesql/src/compile/mod.rs
3+
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?"
4+
---
5+
+---+---+
6+
| a | b |
7+
+---+---+
8+
| 1 | 2 |
9+
| 3 | 4 |
10+
| 5 | 6 |
11+
+---+---+

0 commit comments

Comments
 (0)