alamb commented on code in PR #3209:
URL: https://github.com/apache/arrow-datafusion/pull/3209#discussion_r950707963
##########
datafusion/core/src/datasource/view.rs:
##########
@@ -134,6 +134,82 @@ mod tests {
Ok(())
}
+ #[tokio::test]
+ async fn query_view_with_alias() -> Result<()> {
+ let session_ctx = SessionContext::with_config(
+ SessionConfig::new().with_information_schema(true),
+ );
+
+ session_ctx
+ .sql("CREATE TABLE abc AS VALUES (1,2,3), (4,5,6)")
+ .await?
+ .collect()
+ .await?;
+
+ let view_sql = "CREATE VIEW xyz AS SELECT column1 AS c1, column2 AS c2
FROM abc";
+ session_ctx.sql(view_sql).await?.collect().await?;
+
+ let results = session_ctx.sql("SELECT * FROM information_schema.tables
WHERE table_type='VIEW' AND table_name = 'xyz'").await?.collect().await?;
+ assert_eq!(results[0].num_rows(), 1);
Review Comment:
I don't think there is anything wrong with checking the information schema
too, but it seems unnecessary as the following line selects directly from the
view
##########
datafusion/core/src/datasource/view.rs:
##########
@@ -134,6 +134,82 @@ mod tests {
Ok(())
}
+ #[tokio::test]
+ async fn query_view_with_alias() -> Result<()> {
+ let session_ctx = SessionContext::with_config(
+ SessionConfig::new().with_information_schema(true),
+ );
+
+ session_ctx
+ .sql("CREATE TABLE abc AS VALUES (1,2,3), (4,5,6)")
+ .await?
+ .collect()
+ .await?;
+
+ let view_sql = "CREATE VIEW xyz AS SELECT column1 AS c1, column2 AS c2
FROM abc";
+ session_ctx.sql(view_sql).await?.collect().await?;
+
+ let results = session_ctx.sql("SELECT * FROM information_schema.tables
WHERE table_type='VIEW' AND table_name = 'xyz'").await?.collect().await?;
+ assert_eq!(results[0].num_rows(), 1);
+
+ let results = session_ctx
+ .sql("SELECT c1 FROM xyz")
+ .await?
+ .collect()
+ .await?;
+
+ let expected = vec![
+ "+----+",
+ "| c1 |",
+ "+----+",
+ "| 1 |",
+ "| 4 |",
+ "+----+",
+ ];
+
+ assert_batches_eq!(expected, &results);
+
+ Ok(())
+ }
+
+ #[tokio::test]
+ async fn query_view_with_inline_alias() -> Result<()> {
+ let session_ctx = SessionContext::with_config(
+ SessionConfig::new().with_information_schema(true),
+ );
+
+ session_ctx
+ .sql("CREATE TABLE abc AS VALUES (1,2,3), (4,5,6)")
+ .await?
+ .collect()
+ .await?;
+
+ let view_sql = "CREATE VIEW xyz (c1, c2) AS SELECT column1, column2
FROM abc";
+ session_ctx.sql(view_sql).await?.collect().await?;
+
+ let results = session_ctx.sql("SELECT * FROM information_schema.tables
WHERE table_type='VIEW' AND table_name = 'xyz'").await?.collect().await?;
+ assert_eq!(results[0].num_rows(), 1);
+
+ let results = session_ctx
+ .sql("SELECT c1 FROM xyz")
Review Comment:
I would recommend something like `SELECT c2, c1 FROM xyz` to also also help
verify the column ordering is handled correctly
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]