Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

renamed .txt to .csv, made input_order work with names, added tests a…

…nd better docs
  • Loading branch information...
commit 29ad1ec1a262e00efda4264825701d3f9da994c6 1 parent 8721f4c
@EvanCarroll authored
View
12 script/bdshell
@@ -204,13 +204,14 @@ sub process_action_copy {
## This code works if you have a header in the CSV file
## and the column list is specified in the copy-command
- ## then, it lines the two up.
+ ## then, it resolves the names in input_order to
+ ## numerical values
my @arr;
if ( $perl_args->{input_order} !~ /\\/ ) {
- COL: foreach my $col_name ( @{[split ',\s+', $perl_args->{input_order}]} ) {
- for ( my $i = 0; $i <= $#header; $i++ ) {
+ COL: foreach my $col_name ( @{[split ',\s*', $perl_args->{input_order}]} ) {
+ for ( my $i = 0; $i <= @header; $i++ ) {
if ( $header[$i] eq $col_name ) {
- push @arr, $i;
+ push @arr, $i+1; # the \1 is 1 based.
next COL;
}
}
@@ -251,7 +252,6 @@ sub process_action_copy {
my @columns;
- ## If you want ragged you've got ragged:
if ( $perl_args->{input_order} ) {
my @index = ( $perl_args->{input_order} =~ m/\\?(\d+)\s*/g );
## -1 because 1 is the 0th element in the csv
@@ -345,7 +345,7 @@ Column-backreference syntax such as C<\3 \2 \1> for the third column, followed b
=item
-Header name syntax 'colname1,colname2,colname3' which will permit you to load them in the order specified with the names of the columns as they apears in the CSV header row - this format also requires HEADER to be specified.
+Header name syntax 'colname1,colname2,colname3' which will permit you to reorder a CSV file. Specified with the names of the columns as they apears in the CSV header row. This format requires (a) header row in the input file, (b) ether HEADER or -PERL_header to be enabled.
=back
View
15 t/ragged/bdshell_run.sh
@@ -1,14 +1,21 @@
bdshell -d dealermade -c 'TRUNCATE TABLE bdshell_test.ragged;'
## Should die no idea how many columns the table is, can't trucate data
-bdshell -d dealermade -c '\COPY bdshell_test.ragged FROM data/ten_column_load_normal.txt WITH -PERL_ragged'
+bdshell -d dealermade -c '\COPY bdshell_test.ragged FROM data/ten_column_load_normal.csv WITH -PERL_ragged'
## Should insert 1,2,3,4
-bdshell -d dealermade -c '\COPY bdshell_test.ragged ( a, b, c, d ) FROM data/ten_column_load_normal.txt WITH -PERL_ragged'
+bdshell -d dealermade -c '\COPY bdshell_test.ragged ( a, b, c, d ) FROM data/ten_column_load_normal.csv WITH -PERL_ragged'
## Should insert 1,2,3,4
-bdshell -d dealermade -c '\COPY bdshell_test.ragged ( a, b, c, d ) FROM data/ten_column_load_backwards.txt WITH -PERL_input_order "\10 \9 \8 \7"'
+bdshell -d dealermade -c '\COPY bdshell_test.ragged ( a, b, c, d ) FROM data/ten_column_load_backwards.csv WITH -PERL_input_order "\10 \9 \8 \7"'
## Should die no idea on how to handle spaces.
-bdshell -d dealermade -c '\COPY bdshell_test.ragged (a,b , c,d) FROM data/ten_column_load_normal_with_spaces.txt WITH -PERL_ragged'
+bdshell -d dealermade -c '\COPY bdshell_test.ragged (a,b , c,d) FROM data/ten_column_load_normal_with_spaces.csv WITH -PERL_ragged'
+
+bdshell -d dealermade -c '\COPY bdshell_test.ragged (d,c,b,a) FROM data/ten_column_load_normal_header.csv WITH -PERL_header -PERL_input_order="d, c, b, a"'
+
+bdshell -d dealermade -c '\COPY bdshell_test.ragged (a,b,c,d) FROM data/ten_column_load_normal_header.csv WITH -PERL_header -PERL_input_order="a, b, c, d"'
+
+bdshell -d dealermade -c '\COPY bdshell_test.ragged (a,b,c,d) FROM data/ten_column_load_backwards_header.csv WITH -PERL_header -PERL_input_order="a, b, c, d"'
+
View
0  t/ragged/data/ten_column_load_backwards.txt → t/ragged/data/ten_column_load_backwards.csv
File renamed without changes
View
3  t/ragged/data/ten_column_load_backwards_header.csv
@@ -0,0 +1,3 @@
+j,i,h,g,f,e,d,c,b,a
+10,9,8,7,6,5,4,3,2,1
+10,9,8,7,6,5,4,3,2,1
View
0  t/ragged/data/ten_column_load_normal.txt → t/ragged/data/ten_column_load_normal.csv
File renamed without changes
View
3  t/ragged/data/ten_column_load_normal_header.csv
@@ -0,0 +1,3 @@
+a,b,c,d,e,f,g,h,i,j
+1,2,3,4,5,6,7,8,9,10
+1,2,3,4,5,6,7,8,9,10
View
0  t/ragged/data/ten_column_load_normal_with_spaces.txt → t/ragged/data/ten_column_load_normal_with_spaces.csv
File renamed without changes
Please sign in to comment.
Something went wrong with that request. Please try again.