Skip to content

Commit d55fb3a

Browse files
committed
address comments
1 parent 6a1486d commit d55fb3a

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed

crates/catalog/glue/src/catalog.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,12 @@ impl Catalog for GlueCatalog {
384384
Some(location) => location.clone(),
385385
None => {
386386
let ns = self.get_namespace(namespace).await?;
387-
get_default_table_location(&ns, &db_name, &table_name, &self.config.warehouse)
387+
let location =
388+
get_default_table_location(&ns, &db_name, &table_name, &self.config.warehouse);
389+
creation.location = Some(location.clone());
390+
location
388391
}
389392
};
390-
creation.location = Some(location.clone());
391393
let metadata = TableMetadataBuilder::from_table_creation(creation)?
392394
.build()?
393395
.metadata;

crates/catalog/glue/tests/glue_catalog_test.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ async fn set_test_namespace(catalog: &GlueCatalog, namespace: &NamespaceIdent) -
105105
Ok(())
106106
}
107107

108-
fn set_table_creation(name: impl ToString) -> Result<TableCreation> {
108+
fn set_table_creation(location: Option<String>, name: impl ToString) -> Result<TableCreation> {
109109
let schema = Schema::builder()
110110
.with_schema_id(0)
111111
.with_fields(vec![
@@ -114,19 +114,19 @@ fn set_table_creation(name: impl ToString) -> Result<TableCreation> {
114114
])
115115
.build()?;
116116

117-
let creation = TableCreation::builder()
117+
let builder = TableCreation::builder()
118118
.name(name.to_string())
119119
.properties(HashMap::new())
120-
.schema(schema)
121-
.build();
120+
.location_opt(location)
121+
.schema(schema);
122122

123-
Ok(creation)
123+
Ok(builder.build())
124124
}
125125

126126
#[tokio::test]
127127
async fn test_rename_table() -> Result<()> {
128128
let catalog = get_catalog().await;
129-
let creation = set_table_creation("my_table")?;
129+
let creation = set_table_creation(None, "my_table")?;
130130
let namespace = Namespace::new(NamespaceIdent::new("test_rename_table".into()));
131131

132132
catalog
@@ -153,7 +153,7 @@ async fn test_rename_table() -> Result<()> {
153153
#[tokio::test]
154154
async fn test_table_exists() -> Result<()> {
155155
let catalog = get_catalog().await;
156-
let creation = set_table_creation("my_table")?;
156+
let creation = set_table_creation(None, "my_table")?;
157157
let namespace = Namespace::new(NamespaceIdent::new("test_table_exists".into()));
158158

159159
catalog
@@ -177,7 +177,7 @@ async fn test_table_exists() -> Result<()> {
177177
#[tokio::test]
178178
async fn test_drop_table() -> Result<()> {
179179
let catalog = get_catalog().await;
180-
let creation = set_table_creation("my_table")?;
180+
let creation = set_table_creation(None, "my_table")?;
181181
let namespace = Namespace::new(NamespaceIdent::new("test_drop_table".into()));
182182

183183
catalog
@@ -198,7 +198,7 @@ async fn test_drop_table() -> Result<()> {
198198
#[tokio::test]
199199
async fn test_load_table() -> Result<()> {
200200
let catalog = get_catalog().await;
201-
let creation = set_table_creation("my_table")?;
201+
let creation = set_table_creation(None, "my_table")?;
202202
let namespace = Namespace::new(NamespaceIdent::new("test_load_table".into()));
203203

204204
catalog
@@ -226,10 +226,8 @@ async fn test_create_table() -> Result<()> {
226226
let catalog = get_catalog().await;
227227
let namespace = NamespaceIdent::new("test_create_table".to_string());
228228
set_test_namespace(&catalog, &namespace).await?;
229-
let mut creation = set_table_creation("my_table")?;
230229
// inject custom location, ignore the namespace prefix
231-
creation.location = Some("s3a://warehouse/hive".to_string());
232-
230+
let creation = set_table_creation(Some("s3a://warehouse/hive".into()), "my_table")?;
233231
let result = catalog.create_table(&namespace, creation).await?;
234232

235233
assert_eq!(result.identifier().name(), "my_table");

crates/catalog/hms/src/catalog.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,11 @@ impl Catalog for HmsCatalog {
342342
Some(location) => location.clone(),
343343
None => {
344344
let ns = self.get_namespace(namespace).await?;
345-
get_default_table_location(&ns, &table_name, &self.config.warehouse)
345+
let location = get_default_table_location(&ns, &table_name, &self.config.warehouse);
346+
creation.location = Some(location.clone());
347+
location
346348
}
347349
};
348-
creation.location = Some(location.clone());
349350
let metadata = TableMetadataBuilder::from_table_creation(creation)?
350351
.build()?
351352
.metadata;

crates/catalog/hms/tests/hms_catalog_test.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ async fn set_test_namespace(catalog: &HmsCatalog, namespace: &NamespaceIdent) ->
101101
Ok(())
102102
}
103103

104-
fn set_table_creation(name: impl ToString) -> Result<TableCreation> {
104+
fn set_table_creation(location: Option<String>, name: impl ToString) -> Result<TableCreation> {
105105
let schema = Schema::builder()
106106
.with_schema_id(0)
107107
.with_fields(vec![
@@ -110,19 +110,19 @@ fn set_table_creation(name: impl ToString) -> Result<TableCreation> {
110110
])
111111
.build()?;
112112

113-
let creation = TableCreation::builder()
113+
let builder = TableCreation::builder()
114114
.name(name.to_string())
115115
.properties(HashMap::new())
116-
.schema(schema)
117-
.build();
116+
.location_opt(location)
117+
.schema(schema);
118118

119-
Ok(creation)
119+
Ok(builder.build())
120120
}
121121

122122
#[tokio::test]
123123
async fn test_rename_table() -> Result<()> {
124124
let catalog = get_catalog().await;
125-
let creation: TableCreation = set_table_creation("my_table")?;
125+
let creation: TableCreation = set_table_creation(None, "my_table")?;
126126
let namespace = Namespace::new(NamespaceIdent::new("test_rename_table".into()));
127127
set_test_namespace(&catalog, namespace.name()).await?;
128128

@@ -142,7 +142,7 @@ async fn test_rename_table() -> Result<()> {
142142
#[tokio::test]
143143
async fn test_table_exists() -> Result<()> {
144144
let catalog = get_catalog().await;
145-
let creation = set_table_creation("my_table")?;
145+
let creation = set_table_creation(None, "my_table")?;
146146
let namespace = Namespace::new(NamespaceIdent::new("test_table_exists".into()));
147147
set_test_namespace(&catalog, namespace.name()).await?;
148148

@@ -158,7 +158,7 @@ async fn test_table_exists() -> Result<()> {
158158
#[tokio::test]
159159
async fn test_drop_table() -> Result<()> {
160160
let catalog = get_catalog().await;
161-
let creation = set_table_creation("my_table")?;
161+
let creation = set_table_creation(None, "my_table")?;
162162
let namespace = Namespace::new(NamespaceIdent::new("test_drop_table".into()));
163163
set_test_namespace(&catalog, namespace.name()).await?;
164164

@@ -176,7 +176,7 @@ async fn test_drop_table() -> Result<()> {
176176
#[tokio::test]
177177
async fn test_load_table() -> Result<()> {
178178
let catalog = get_catalog().await;
179-
let creation = set_table_creation("my_table")?;
179+
let creation = set_table_creation(None, "my_table")?;
180180
let namespace = Namespace::new(NamespaceIdent::new("test_load_table".into()));
181181
set_test_namespace(&catalog, namespace.name()).await?;
182182

@@ -199,9 +199,8 @@ async fn test_load_table() -> Result<()> {
199199
#[tokio::test]
200200
async fn test_create_table() -> Result<()> {
201201
let catalog = get_catalog().await;
202-
let mut creation = set_table_creation("my_table")?;
203202
// inject custom location, ignore the namespace prefix
204-
creation.location = Some("s3a://warehouse/hive".to_string());
203+
let creation = set_table_creation(Some("s3a://warehouse/hive".into()), "my_table")?;
205204
let namespace = Namespace::new(NamespaceIdent::new("test_create_table".into()));
206205
set_test_namespace(&catalog, namespace.name()).await?;
207206

@@ -230,7 +229,7 @@ async fn test_list_tables() -> Result<()> {
230229

231230
assert_eq!(result, vec![]);
232231

233-
let creation = set_table_creation("my_table")?;
232+
let creation = set_table_creation(None, "my_table")?;
234233
catalog.create_table(ns.name(), creation).await?;
235234
let result = catalog.list_tables(ns.name()).await?;
236235

0 commit comments

Comments
 (0)