Start working on integration tests for updating tables
This commit is contained in:
parent
cadd6da179
commit
a9f290c92c
10
src/lib.rs
10
src/lib.rs
|
@ -51,6 +51,16 @@ pub async fn create_table(output_url: Url, schema_path: PathBuf) -> Result<(), a
|
|||
create_table_with_schema(output_url, table_schema).await
|
||||
}
|
||||
|
||||
/*
|
||||
* Take an existing table and update
|
||||
*/
|
||||
pub async fn update_table_with_schema(
|
||||
output_url: Url,
|
||||
table_schema: SchemaTypeStruct,
|
||||
) -> Result<(), anyhow::Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/*
|
||||
* Converts a relative table path into the full table URI based on the provided path in the options
|
||||
*/
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use carto::*;
|
||||
use url::Url;
|
||||
use deltalake::SchemaTypeStruct;
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_create_table() -> Result<(), anyhow::Error> {
|
||||
|
@ -13,12 +12,56 @@ fields:
|
|||
- name: timestamp
|
||||
type: timestamp
|
||||
nullable: false
|
||||
# Make this optional
|
||||
metadata:
|
||||
"#;
|
||||
|
||||
let schema = serde_yaml::from_str(yaml)?;
|
||||
let _table = carto::create_table_with_schema(table_url.clone(), schema).await?;
|
||||
let _loaded = deltalake::open_table(table_url).await?;
|
||||
let schema: SchemaTypeStruct = serde_yaml::from_str(yaml)?;
|
||||
let _ = carto::create_table_with_schema(table_url.clone(), schema.clone()).await?;
|
||||
let mut loaded = deltalake::open_table(table_url).await?;
|
||||
loaded.load().await?;
|
||||
let loaded_schema = loaded.schema().unwrap();
|
||||
assert_eq!(loaded_schema, &schema);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_update_table() -> Result<(), anyhow::Error> {
|
||||
let table_dir = tempfile::tempdir()?;
|
||||
let table_url = carto::filepath_to_url(&table_dir.into_path())?;
|
||||
|
||||
let yaml = r#"
|
||||
---
|
||||
type: struct
|
||||
fields:
|
||||
- name: timestamp
|
||||
type: timestamp
|
||||
nullable: false
|
||||
metadata:
|
||||
"#;
|
||||
|
||||
let schema: SchemaTypeStruct = serde_yaml::from_str(yaml)?;
|
||||
let _ = carto::create_table_with_schema(table_url.clone(), schema.clone()).await?;
|
||||
|
||||
let update_yaml = r#"
|
||||
---
|
||||
type: struct
|
||||
fields:
|
||||
- name: timestamp
|
||||
type: timestamp
|
||||
nullable: false
|
||||
metadata:
|
||||
- name: message
|
||||
type: string
|
||||
nullable: false
|
||||
metadata:
|
||||
"#;
|
||||
|
||||
let schema: SchemaTypeStruct = serde_yaml::from_str(update_yaml)?;
|
||||
let _ = carto::update_table_with_schema(table_url.clone(), schema.clone()).await?;
|
||||
|
||||
let mut loaded = deltalake::open_table(table_url).await?;
|
||||
loaded.load().await?;
|
||||
let loaded_schema = loaded.schema().unwrap();
|
||||
assert_eq!(loaded_schema, &schema);
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue