Skip to content

Commit 78498f0

Browse files
committed
display working, readying for first preview release
1 parent 85edb21 commit 78498f0

File tree

4 files changed

+66
-12
lines changed

4 files changed

+66
-12
lines changed

src/lib/src/api/local/compare.rs

+29-1
Original file line numberDiff line numberDiff line change
@@ -419,11 +419,11 @@ fn compute_row_comparison(
419419
log::debug!("added cols: {:?}", schema_diff.added_cols);
420420
log::debug!("removed cols: {:?}", schema_diff.removed_cols);
421421

422-
// If no keys, then compare on all shared columns
423422
let targets = targets.to_owned();
424423
let keys = keys.to_owned();
425424
let display = display.to_owned();
426425

426+
// If no keys, then compare on all shared columns
427427
let unchanged_cols = schema_diff.unchanged_cols.clone();
428428
let keys = if keys.is_empty() {
429429
unchanged_cols
@@ -434,6 +434,34 @@ fn compute_row_comparison(
434434
keys
435435
};
436436

437+
// TODONOW isolate this
438+
let mut display_default = vec![];
439+
for col in &schema_diff.unchanged_cols {
440+
if !keys.contains(&col.as_str()) && !targets.contains(&col.as_str()) {
441+
display_default.push(format!("{}.left", col));
442+
display_default.push(format!("{}.right", col));
443+
}
444+
}
445+
for col in &schema_diff.removed_cols {
446+
display_default.push(format!("{}.left", col));
447+
}
448+
449+
for col in &schema_diff.added_cols {
450+
display_default.push(format!("{}.right", col));
451+
}
452+
453+
// Map this to a Vec<&str>
454+
let display_default = display_default
455+
.iter()
456+
.map(|s| s.as_str())
457+
.collect::<Vec<&str>>();
458+
459+
let display = if display.is_empty() {
460+
display_default
461+
} else {
462+
display
463+
};
464+
437465
// TODO: unsure if hash comparison or join is faster here - would guess join, could use some testing
438466
let (df_1, df_2) = hash_dfs(df_1.clone(), df_2.clone(), keys.clone(), targets.clone())?;
439467

src/lib/src/model/compare/tabular_compare.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub struct TabularCompareBody {
2424
pub right: TabularCompareResourceBody,
2525
pub keys: Vec<TabularCompareFieldBody>,
2626
pub compare: Vec<TabularCompareFieldBody>,
27-
pub display: Vec<TabularCompareFieldBody>,
27+
pub display: Vec<TabularCompareDisplayBody>,
2828
}
2929

3030
#[derive(Deserialize, Serialize, Debug, Clone)]
@@ -39,3 +39,10 @@ pub struct TabularCompareFieldBody {
3939
pub right: String,
4040
pub alias: Option<String>,
4141
}
42+
43+
#[derive(Deserialize, Serialize, Debug, Clone)]
44+
pub struct TabularCompareDisplayBody {
45+
pub left: Option<String>,
46+
pub right: Option<String>,
47+
pub compare_method: Option<String>,
48+
}

src/lib/src/view/json_data_frame_view.rs

-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ pub struct DerivedDFResource {
6363
pub resource_id: String,
6464
pub path: String,
6565
pub resource_type: DFResourceType,
66-
pub name: String,
6766
}
6867

6968
impl JsonDataFrameSource {

src/server/src/controllers/compare.rs

+29-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use liboxen::core::df::tabular;
77
use liboxen::core::index::{CommitReader, Merger};
88
use liboxen::error::OxenError;
99
use liboxen::message::OxenMessage;
10-
use liboxen::model::compare::tabular_compare::TabularCompareBody;
10+
use liboxen::model::compare::tabular_compare::{TabularCompareBody, TabularCompareDisplayBody};
1111
use liboxen::model::{Commit, DataFrameSize, LocalRepository, Schema};
1212
use liboxen::opts::df_opts::DFOptsView;
1313
use liboxen::opts::DFOpts;
@@ -195,6 +195,14 @@ pub async fn create_df_compare(
195195
let resource_2 = PathBuf::from(data.right.path);
196196
let keys = data.keys;
197197
let targets = data.compare;
198+
let display = data.display;
199+
200+
log::debug!("display is {:?}", display);
201+
202+
let display_by_column = get_display_by_columns(display);
203+
204+
log::debug!("display by col is {:?}", display_by_column);
205+
198206
let compare_id = data.compare_id;
199207

200208
let commit_1 = api::local::revisions::get(&repository, &data.left.version)?
@@ -233,7 +241,7 @@ pub async fn create_df_compare(
233241
cpath_2,
234242
keys,
235243
targets,
236-
vec![], // TODONOW: add display handling here
244+
display_by_column, // TODONOW: add display handling here
237245
None,
238246
)?;
239247

@@ -331,6 +339,9 @@ pub async fn get_df_compare(
331339
// different keys and targets from left and right file.
332340
let keys = data.keys.iter().map(|k| k.left.clone()).collect();
333341
let targets = data.compare.iter().map(|t| t.left.clone()).collect();
342+
let display = data.display;
343+
344+
let display_by_column = get_display_by_columns(display);
334345

335346
let result = api::local::compare::compare_files(
336347
&repository,
@@ -339,8 +350,7 @@ pub async fn get_df_compare(
339350
cpath_2,
340351
keys,
341352
targets,
342-
// TODONOW
343-
vec![],
353+
display_by_column,
344354
None,
345355
)?;
346356

@@ -369,18 +379,16 @@ pub async fn get_derived_df(
369379
req: HttpRequest,
370380
query: web::Query<DFOptsQuery>,
371381
) -> Result<HttpResponse, OxenHttpError> {
372-
log::debug!("in derived df compare");
373382
let app_data = app_data(&req)?;
374383
let namespace = path_param(&req, "namespace")?;
375384
let repo_name = path_param(&req, "repo_name")?;
376385
let repo = get_repo(&app_data.path, namespace, repo_name)?;
377386
let compare_id = path_param(&req, "compare_id")?;
378-
let path = path_param(&req, "path")?;
379387
let base_head = path_param(&req, "base_head")?;
380388

381389
let compare_dir = api::local::compare::get_compare_dir(&repo, &compare_id);
382390

383-
let derived_df_path = compare_dir.join(format!("{}.parquet", path));
391+
let derived_df_path = compare_dir.join("diff.parquet");
384392

385393
// TODO: If this structure holds for diff + query, there is some amt of reusability with
386394
// controllers::df::get logic
@@ -463,9 +471,8 @@ pub async fn get_derived_df(
463471

464472
let derived_resource = DerivedDFResource {
465473
resource_type: DFResourceType::Compare,
466-
name: path.clone(),
467474
resource_id: compare_id.clone(),
468-
path: format!("/compare/data_frame/{}/{}/{}", compare_id, path, base_head),
475+
path: format!("/compare/data_frame/{}/{}", compare_id, base_head),
469476
};
470477

471478
let response = JsonDataFrameViewResponse {
@@ -537,3 +544,16 @@ fn parse_base_head_resource(
537544

538545
Ok((base_commit, head_commit, resource))
539546
}
547+
548+
fn get_display_by_columns(display: Vec<TabularCompareDisplayBody>) -> Vec<String> {
549+
let mut display_by_column = vec![];
550+
for d in display {
551+
if let Some(left) = d.left {
552+
display_by_column.push(format!("{}.left", left));
553+
}
554+
if let Some(right) = d.right {
555+
display_by_column.push(format!("{}.right", right));
556+
}
557+
}
558+
display_by_column
559+
}

0 commit comments

Comments
 (0)