Skip to content

Commit

Permalink
Add format field to DataSyncCommand (#764)
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeiPatiakin authored Dec 17, 2024
1 parent 22ab168 commit 18025ea
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions clade/proto/sync.proto
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ message DataSyncCommand {
// Monotonically-increasing transaction number.
// Only specified in the last message of a transaction
optional uint64 sequence_number = 5;

// Table format
schema.TableFormat format = 6;
}

message DataSyncResponse {
Expand Down
7 changes: 6 additions & 1 deletion src/frontend/flight/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use arrow::record_batch::RecordBatch;
use arrow_flight::sql::metadata::{SqlInfoData, SqlInfoDataBuilder};
use arrow_flight::sql::{ProstMessageExt, SqlInfo, TicketStatementQuery};
use arrow_flight::{FlightDescriptor, FlightEndpoint, FlightInfo, Ticket};
use clade::schema::TableFormat;
use clade::sync::{DataSyncCommand, DataSyncResponse};
use dashmap::DashMap;
use datafusion::common::Result;
Expand All @@ -22,7 +23,7 @@ use url::Url;
use crate::context::SeafowlContext;
use crate::sync::schema::SyncSchema;
use crate::sync::writer::SeafowlDataSyncWriter;
use crate::sync::SyncResult;
use crate::sync::{SyncError, SyncResult};

lazy_static! {
pub static ref SEAFOWL_SQL_DATA: SqlInfoData = {
Expand Down Expand Up @@ -162,6 +163,10 @@ impl SeafowlFlightHandler {
});
}

if cmd.format != TableFormat::Delta as i32 {
return Err(SyncError::NotImplemented);
}

let log_store = match cmd.store {
None => self
.context
Expand Down
3 changes: 3 additions & 0 deletions src/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ pub enum SyncError {
#[error("Invalid sync message: {reason}")]
InvalidMessage { reason: String },

#[error("Not implemented")]
NotImplemented,

#[error(transparent)]
ArrowError(#[from] arrow_schema::ArrowError),

Expand Down
4 changes: 3 additions & 1 deletion tests/flight/sync.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::fixtures::minio_options;
use crate::flight::*;
use clade::schema::StorageLocation;
use clade::schema::{StorageLocation, TableFormat};
use clade::sync::{ColumnDescriptor, ColumnRole};
use deltalake::DeltaTable;
use std::collections::HashMap;
Expand Down Expand Up @@ -118,6 +118,7 @@ async fn test_sync_happy_path() -> std::result::Result<(), Box<dyn std::error::E
column_descriptors,
origin: "42".to_string(),
sequence_number: None,
format: TableFormat::Delta.into(),
};

// Changes are still in memory
Expand Down Expand Up @@ -569,6 +570,7 @@ async fn test_sync_custom_store(
column_descriptors,
origin: "42".to_string(),
sequence_number: Some(1000),
format: TableFormat::Delta.into(),
};

let sync_result = do_put_sync(cmd.clone(), batch.clone(), &mut client).await?;
Expand Down
6 changes: 5 additions & 1 deletion tests/flight/sync_fail.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::flight::*;
use clade::sync::{ColumnDescriptor, ColumnRole};
use clade::{
schema::TableFormat,
sync::{ColumnDescriptor, ColumnRole},
};

async fn assert_sync_error(
cmd: DataSyncCommand,
Expand Down Expand Up @@ -36,6 +39,7 @@ async fn test_sync_errors() -> std::result::Result<(), Box<dyn std::error::Error
column_descriptors: vec![],
origin: "1".to_string(),
sequence_number: Some(42),
format: TableFormat::Delta.into(),
};

// No column descriptors provided
Expand Down

0 comments on commit 18025ea

Please sign in to comment.