Skip to content

Commit

Permalink
Merge pull request #1906 from jqnatividad/column-selector-emoji
Browse files Browse the repository at this point in the history
`docs`: add column selector emoji - 👆
  • Loading branch information
jqnatividad authored Jun 22, 2024
2 parents a8610c0 + 40ac8a7 commit 50b89c8
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 24 deletions.
43 changes: 22 additions & 21 deletions README.md

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/cmd/geocode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ geocode arguments:
For reverse, it must be a column using WGS 84 coordinates in
"lat, long" or "(lat, long)" format.
For countryinfo, it must be a column with a ISO 3166-1 alpha-2 country code.
Note that you can use column selector syntax to select the column, but only
the first column will be used. See `select --help` for more information.
<location> The location to geocode for suggestnow, reversenow & countryinfonow subcommands.
For suggestnow, its a City string pattern.
Expand Down
4 changes: 4 additions & 0 deletions src/cmd/partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ Usage:
partition arguments:
<column> The column to use as a key for partitioning.
You can use the `--select` option to select
the column by name or index, but only one
column can be used for partitioning.
See `select` command for more details.
<outdir> The directory to write the output files to.
<input> The CSV file to read from. If not specified, then
the input will be read from stdin.
Expand Down
7 changes: 7 additions & 0 deletions src/cmd/pseudo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ Usage:
qsv pseudo [options] <column> [<input>]
qsv pseudo --help
pseudo arguments:
<column> The column to pseudonymise. You can use the `--select`
option to select the column by name or index.
See `select` command for more details.
<input> The CSV file to read from. If not specified, then
the input will be read from stdin.
Common options:
-h, --help Display this message
--start <number> The starting number for the incremental identifier.
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/search.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
static USAGE: &str = r#"
Filters CSV data by whether the given regex matches a row.
The regex is applied to each field in each row, and if any field matches,
The regex is applied to selected field in each row, and if any field matches,
then the row is written to the output, and the number of matches to stderr.
The columns to search can be limited with the '--select' flag (but the full row
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/select.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
static USAGE: &str = r#"
Select columns from CSV data efficiently.
This command lets you manipulate the columns in CSV data. You can re-order
them, duplicate them or drop them. Columns can be referenced by index or by
This command lets you manipulate the columns in CSV data. You can re-order,
duplicate, reverse or drop them. Columns can be referenced by index or by
name if there is a header row (duplicate column names can be disambiguated with
more indexing). Column ranges can also be specified. Finally, columns can be
selected using regular expressions.
Expand Down
46 changes: 46 additions & 0 deletions tests/test_geocode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,52 @@ fn geocode_suggest() {
assert_eq!(got, expected);
}

#[test]
fn geocode_suggest_select() {
let wrk = Workdir::new("geocode_suggest_select");
wrk.create(
"data.csv",
vec![
svec!["c1", "c2", "Location"],
svec!["1", "2", "Melrose, New York"],
svec!["3", "4", "East Flatbush, New York"],
svec!["5", "6", "Manhattan, New York"],
svec!["7", "8", "Brooklyn, New York"],
svec!["9", "10", "East Harlem, New York"],
svec![
"11",
"12",
"This is not a Location and it will not be geocoded"
],
svec!["13", "14", "Jersey City, New Jersey"],
svec!["15", "16", "95.213424, 190,1234565"], // invalid lat, long
svec!["17", "18", "Makati, Metro Manila, Philippines"],
],
);
let mut cmd = wrk.command("geocode");
// use select syntax to select the last column
cmd.arg("suggest").arg("_").arg("data.csv");

let got: Vec<Vec<String>> = wrk.read_stdout(&mut cmd);
let expected = vec![
svec!["c1", "c2", "Location"],
svec!["1", "2", "(41.90059, -87.85673)"],
svec!["3", "4", "(28.11085, -82.69482)"],
svec!["5", "6", "(40.71427, -74.00597)"],
svec!["7", "8", "(45.09413, -93.35634)"],
svec!["9", "10", "(40.79472, -73.9425)"],
svec![
"11",
"12",
"This is not a Location and it will not be geocoded"
],
svec!["13", "14", "(40.72816, -74.07764)"],
svec!["15", "16", "95.213424, 190,1234565"], // suggest expects a city name, not lat, long
svec!["17", "18", "(14.55027, 121.03269)"],
];
assert_eq!(got, expected);
}

#[test]
fn geocode_suggestnow_default() {
let wrk = Workdir::new("geocode_suggestnow_default");
Expand Down

0 comments on commit 50b89c8

Please sign in to comment.