Skip to content

Commit cb238e2

Browse files
committed
Merge branch 'hms-location' into dev
2 parents 4b1da60 + 6a1486d commit cb238e2

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

crates/catalog/glue/src/catalog.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl Catalog for GlueCatalog {
172172
///
173173
/// - Errors from `validate_namespace` if the namespace identifier does not
174174
/// meet validation criteria.
175-
/// - Errors from `convert_to_database` if the properties cannot be
175+
/// - Errors from `convert_to_database` if the properties cannot be
176176
/// successfully converted into a database configuration.
177177
/// - Errors from the underlying database creation process, converted using
178178
/// `from_sdk_error`.
@@ -259,7 +259,7 @@ impl Catalog for GlueCatalog {
259259
/// Asynchronously updates properties of an existing namespace.
260260
///
261261
/// Converts the given namespace identifier and properties into a database
262-
/// representation and then attempts to update the corresponding namespace
262+
/// representation and then attempts to update the corresponding namespace
263263
/// in the Glue Catalog.
264264
///
265265
/// # Returns
@@ -295,7 +295,7 @@ impl Catalog for GlueCatalog {
295295
/// # Returns
296296
/// A `Result<()>` indicating the outcome:
297297
/// - `Ok(())` signifies successful namespace deletion.
298-
/// - `Err(...)` signifies failure to drop the namespace due to validation
298+
/// - `Err(...)` signifies failure to drop the namespace due to validation
299299
/// errors, connectivity issues, or Glue Catalog constraints.
300300
async fn drop_namespace(&self, namespace: &NamespaceIdent) -> Result<()> {
301301
let db_name = validate_namespace(namespace)?;
@@ -322,7 +322,7 @@ impl Catalog for GlueCatalog {
322322
/// A `Result<Vec<TableIdent>>`, which is:
323323
/// - `Ok(vec![...])` containing a vector of `TableIdent` instances, each
324324
/// representing a table within the specified namespace.
325-
/// - `Err(...)` if an error occurs during namespace validation or while
325+
/// - `Err(...)` if an error occurs during namespace validation or while
326326
/// querying the database.
327327
async fn list_tables(&self, namespace: &NamespaceIdent) -> Result<Vec<TableIdent>> {
328328
let db_name = validate_namespace(namespace)?;
@@ -375,7 +375,7 @@ impl Catalog for GlueCatalog {
375375
async fn create_table(
376376
&self,
377377
namespace: &NamespaceIdent,
378-
creation: TableCreation,
378+
mut creation: TableCreation,
379379
) -> Result<Table> {
380380
let db_name = validate_namespace(namespace)?;
381381
let table_name = creation.name.clone();
@@ -387,7 +387,7 @@ impl Catalog for GlueCatalog {
387387
get_default_table_location(&ns, &db_name, &table_name, &self.config.warehouse)
388388
}
389389
};
390-
390+
creation.location = Some(location.clone());
391391
let metadata = TableMetadataBuilder::from_table_creation(creation)?
392392
.build()?
393393
.metadata;

crates/catalog/glue/tests/glue_catalog_test.rs

Lines changed: 8 additions & 7 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(location: impl ToString, name: impl ToString) -> Result<TableCreation> {
108+
fn set_table_creation(name: impl ToString) -> Result<TableCreation> {
109109
let schema = Schema::builder()
110110
.with_schema_id(0)
111111
.with_fields(vec![
@@ -115,7 +115,6 @@ fn set_table_creation(location: impl ToString, name: impl ToString) -> Result<Ta
115115
.build()?;
116116

117117
let creation = TableCreation::builder()
118-
.location(location.to_string())
119118
.name(name.to_string())
120119
.properties(HashMap::new())
121120
.schema(schema)
@@ -127,7 +126,7 @@ fn set_table_creation(location: impl ToString, name: impl ToString) -> Result<Ta
127126
#[tokio::test]
128127
async fn test_rename_table() -> Result<()> {
129128
let catalog = get_catalog().await;
130-
let creation = set_table_creation("s3a://warehouse/hive", "my_table")?;
129+
let creation = set_table_creation("my_table")?;
131130
let namespace = Namespace::new(NamespaceIdent::new("test_rename_table".into()));
132131

133132
catalog
@@ -154,7 +153,7 @@ async fn test_rename_table() -> Result<()> {
154153
#[tokio::test]
155154
async fn test_table_exists() -> Result<()> {
156155
let catalog = get_catalog().await;
157-
let creation = set_table_creation("s3a://warehouse/hive", "my_table")?;
156+
let creation = set_table_creation("my_table")?;
158157
let namespace = Namespace::new(NamespaceIdent::new("test_table_exists".into()));
159158

160159
catalog
@@ -178,7 +177,7 @@ async fn test_table_exists() -> Result<()> {
178177
#[tokio::test]
179178
async fn test_drop_table() -> Result<()> {
180179
let catalog = get_catalog().await;
181-
let creation = set_table_creation("s3a://warehouse/hive", "my_table")?;
180+
let creation = set_table_creation("my_table")?;
182181
let namespace = Namespace::new(NamespaceIdent::new("test_drop_table".into()));
183182

184183
catalog
@@ -199,7 +198,7 @@ async fn test_drop_table() -> Result<()> {
199198
#[tokio::test]
200199
async fn test_load_table() -> Result<()> {
201200
let catalog = get_catalog().await;
202-
let creation = set_table_creation("s3a://warehouse/hive", "my_table")?;
201+
let creation = set_table_creation("my_table")?;
203202
let namespace = Namespace::new(NamespaceIdent::new("test_load_table".into()));
204203

205204
catalog
@@ -227,7 +226,9 @@ async fn test_create_table() -> Result<()> {
227226
let catalog = get_catalog().await;
228227
let namespace = NamespaceIdent::new("test_create_table".to_string());
229228
set_test_namespace(&catalog, &namespace).await?;
230-
let creation = set_table_creation("s3a://warehouse/hive", "my_table")?;
229+
let mut creation = set_table_creation("my_table")?;
230+
// inject custom location, ignore the namespace prefix
231+
creation.location = Some("s3a://warehouse/hive".to_string());
231232

232233
let result = catalog.create_table(&namespace, creation).await?;
233234

crates/catalog/hms/src/catalog.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -338,16 +338,14 @@ impl Catalog for HmsCatalog {
338338
let db_name = validate_namespace(namespace)?;
339339
let table_name = creation.name.clone();
340340

341-
if creation.location.is_none() {
342-
let ns = self.get_namespace(namespace).await?;
343-
creation.location = Some(get_default_table_location(
344-
&ns,
345-
&table_name,
346-
&self.config.warehouse,
347-
));
348-
}
349-
350-
let location = creation.location.clone().unwrap();
341+
let location = match &creation.location {
342+
Some(location) => location.clone(),
343+
None => {
344+
let ns = self.get_namespace(namespace).await?;
345+
get_default_table_location(&ns, &table_name, &self.config.warehouse)
346+
}
347+
};
348+
creation.location = Some(location.clone());
351349
let metadata = TableMetadataBuilder::from_table_creation(creation)?
352350
.build()?
353351
.metadata;

0 commit comments

Comments
 (0)