NoahKusaba commented on code in PR #2784:
URL:
https://github.com/apache/datafusion-ballista/pull/2784#discussion_r4648062492
##########
integrations/iceberg/tests/scan.rs:
##########
@@ -42,36 +44,172 @@ mod standalone {
assert_standalone_scans(memory_catalog(dir.path()).await).await
}
- // A known limitation: a view stores its planned query, and tables are
- // pinned when a query is planned.
#[tokio::test]
- async fn should_keep_a_views_version() -> Result<()> {
+ async fn should_read_a_views_latest_version() -> Result<()> {
let dir = tempfile::tempdir()?;
- let catalog = memory_catalog(dir.path()).await;
- let state = SessionStateBuilder::new()
- .with_config(SessionConfig::new_with_ballista())
- .with_default_features()
- .build();
- let ctx =
SessionContext::standalone_with_state(register_iceberg(state)).await?;
- ctx.register_table("t", Arc::new(catalog_table(&catalog).await))?;
+ let (catalog, ctx) = view_context(dir.path()).await?;
insert(&catalog, "(1, 'a')").await;
ctx.sql("CREATE VIEW v AS SELECT * FROM t").await?;
+ // A view over a view, reading `t` again in a subquery.
+ ctx.sql("CREATE VIEW w AS SELECT * FROM v WHERE id IN (SELECT id FROM
t)")
+ .await?;
+ insert(&catalog, "(2, 'b')").await;
+
+ for view in ["v", "w"] {
+ let sql = format!("SELECT * FROM {view} ORDER BY id");
+ let result = ctx.sql(&sql).await?.collect().await?;
+ assert_batches_eq!(LATEST, &result);
+ }
+
+ Ok(())
+ }
+
+ #[tokio::test]
+ async fn should_read_a_dataframe_views_latest_version() -> Result<()> {
+ let dir = tempfile::tempdir()?;
+ let (catalog, ctx) = view_context(dir.path()).await?;
+
+ insert(&catalog, "(1, 'a')").await;
+ let df = ctx.sql("SELECT * FROM t").await?;
+ ctx.register_table("v", df.clone().into_view())?;
+ ctx.register_table("tv", df.into_temporary_view())?;
insert(&catalog, "(2, 'b')").await;
- let result = ctx.sql("SELECT * FROM v").await?.collect().await?;
+ for (view, table_type) in [("v", TableType::View), ("tv",
TableType::Temporary)] {
+ let sql = format!("SELECT * FROM {view} ORDER BY id");
+ let result = ctx.sql(&sql).await?.collect().await?;
+ assert_batches_eq!(LATEST, &result);
+ assert_eq!(ctx.table_provider(view).await?.table_type(),
table_type);
+ }
+
+ Ok(())
+ }
+
+ #[tokio::test]
+ async fn should_read_a_view_created_while_its_table_was_gone() ->
Result<()> {
+ let dir = tempfile::tempdir()?;
+ let (catalog, ctx) = view_context(dir.path()).await?;
+
+ insert(&catalog, "(1, 'a')").await;
+ ctx.sql("CREATE VIEW v AS SELECT * FROM t").await?;
+ // While `t` is gone, `w` is created over `v`, and reading it fails.
+ rename_table(&catalog, "t", "gone").await;
+ ctx.sql("CREATE VIEW w AS SELECT * FROM v").await?;
+ assert_table_gone(&ctx, "SELECT * FROM w").await;
+ // Once `t` is back, `w` reads its latest version.
+ rename_table(&catalog, "gone", "t").await;
+ insert(&catalog, "(2, 'b')").await;
+ let result = ctx
+ .sql("SELECT * FROM w ORDER BY id")
+ .await?
+ .collect()
+ .await?;
+ assert_batches_eq!(LATEST, &result);
+
+ Ok(())
+ }
+
+ #[tokio::test]
+ async fn should_fail_to_read_a_view_whose_table_is_gone() -> Result<()> {
+ let dir = tempfile::tempdir()?;
+ let (catalog, ctx) = view_context(dir.path()).await?;
+ ctx.sql("CREATE VIEW v AS SELECT * FROM t").await?;
+ rename_table(&catalog, "t", "gone").await;
+
+ // Without a filter, the client fails to encode the view's scan.
+ assert_table_gone(&ctx, "SELECT * FROM v").await;
+ // With one, pushing the filter into the view's scan fails first.
+ assert_eq!(
Review Comment:
Fixed!
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]