@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414limitations under the License.
1515*/
1616
17- use std:: { collections:: HashMap , fmt :: Write , time:: Duration } ;
17+ use std:: { collections:: HashMap , time:: Duration } ;
1818
1919use anyhow:: { Result , anyhow} ;
2020use async_trait:: async_trait;
@@ -362,17 +362,24 @@ impl Handler for DatabricksAdapter {
362362 . map_err ( |e| format ! ( "Invalid dataset '{dataset_name}' config: {e}" ) ) ?;
363363
364364 let table_name = dataset_name;
365- let mut sql = String :: new ( ) ;
366- let _ = write ! (
367- sql,
368- "CREATE OR REPLACE TABLE {}.{}.{} USING PARQUET LOCATION {}" ,
365+ let fqn = format ! (
366+ "{}.{}.{}" ,
369367 Self :: quoted_identifier( & self . config. catalog) ,
370368 Self :: quoted_identifier( & self . config. schema) ,
371369 Self :: quoted_identifier( & table_name) ,
370+ ) ;
371+
372+ let drop_sql = format ! ( "DROP TABLE IF EXISTS {fqn}" ) ;
373+ self . execute_sql ( & drop_sql)
374+ . await
375+ . map_err ( |e| format ! ( "Failed to drop existing table '{table_name}': {e}" ) ) ?;
376+
377+ let create_sql = format ! (
378+ "CREATE TABLE {fqn} USING PARQUET LOCATION {}" ,
372379 Self :: sql_string_literal( & location)
373380 ) ;
374381
375- self . execute_sql ( & sql )
382+ self . execute_sql ( & create_sql )
376383 . await
377384 . map_err ( |e| format ! ( "Failed to create table '{table_name}': {e}" ) ) ?;
378385
0 commit comments