Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: rendering of columns in convert #110

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/exporters/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{
column::ValueBacking,
compiler::{ColumnRef, ConstraintSet, Kind},
pretty::{Base, Pretty},
structs::Handle,
};
use anyhow::*;
use itertools::Itertools;
Expand Down Expand Up @@ -33,25 +34,26 @@ pub(crate) fn to_csv(cs: &ConstraintSet, exclude: &[String], filename: &str) ->
let mut file = BufWriter::new(File::create(&filename)?);

info!("Exporting {}", module);
let column_names = cs
let (column_refs, column_names): (Vec<ColumnRef>, Vec<Handle>) = cs
.columns
.iter_module(&module)
.map(|c| cs.handle(&c.0))
.sorted()
.collect::<Vec<_>>();
.map(|c| (c.0.clone(), cs.handle(&c.0).clone()))
.sorted_by(|x, y| x.1.cmp(&y.1))
.unzip();

file.write(column_names.iter().map(|h| &h.name).join(",").as_bytes())?;
file.write(&[b'\n'])?;
let max_i = cs.iter_len(&module);
dbg!(&module, cs.iter_len(&module));
for i in 0..max_i {
file.write(
cs.columns
.iter_module(&module)
column_refs
.iter()
.map(|col| {
cs.columns
.get(&col.0, i.try_into().unwrap(), false)
.get(&col, i.try_into().unwrap(), false)
.unwrap_or_default()
.pretty_with_base(col.1.base)
.pretty()
})
.join(",")
.as_bytes(),
Expand Down
8 changes: 2 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
io::{Read, Write},
path::Path,
};
use serde::{Serialize};

Check warning on line 15 in src/main.rs

View workflow job for this annotation

GitHub Actions / build

unused import: `Serialize`

Check warning on line 15 in src/main.rs

View workflow job for this annotation

GitHub Actions / build

unused import: `Serialize`
use serde_json::{Value};

Check warning on line 16 in src/main.rs

View workflow job for this annotation

GitHub Actions / build

unused import: `Value`

Check warning on line 16 in src/main.rs

View workflow job for this annotation

GitHub Actions / build

unused import: `Value`
use transformer::{AutoConstraint, ExpansionLevel};

use clap::{Parser, Subcommand};
Expand Down Expand Up @@ -700,12 +700,8 @@
exclude,
} => {
let mut cs = builder.into_constraint_set()?;
if tracefile.ends_with("lt") {
import::parse_binary_trace(&tracefile, &mut cs, true)
} else {
import::parse_json_trace(&tracefile, &mut cs, true)
}
.with_context(|| format!("while computing from `{}`", tracefile))?;
compute::compute_trace(&tracefile, &mut cs, false)
.with_context(|| format!("while expanding `{}`", tracefile))?;

match format.as_str() {
"csv" => exporters::convert::to_csv(
Expand Down
Loading