diff --git a/bin/q b/bin/q index 62b7894e..a9448760 100755 --- a/bin/q +++ b/bin/q @@ -27,7 +27,7 @@ # # Run with --help for command line details # -q_version = "1.5.0" +q_version = "1.6.0notreleasedyet" __all__ = [ 'QTextAsData' ] @@ -1353,8 +1353,9 @@ class QOutputPrinter(object): data.insert(0,results.metadata.output_column_name_list) for rownum, row in enumerate(data): row_str = [] + skip_formatting = rownum == 0 and self.output_params.output_header for i, col in enumerate(row): - if formatting_dict is not None and str(i + 1) in formatting_dict.keys(): + if formatting_dict is not None and str(i + 1) in formatting_dict.keys() and not skip_formatting: fmt_str = formatting_dict[str(i + 1)] else: if self.output_params.beautify: @@ -1371,6 +1372,9 @@ class QOutputPrinter(object): except (UnicodeEncodeError, UnicodeError), e: print >>sys.stderr, "Cannot encode data. Error:%s" % e sys.exit(3) + except TypeError,e: + print >>sys.stderr, "Error while formatting output: %s" % e + sys.exit(4) except IOError, e: if e.errno == 32: # broken pipe, that's ok diff --git a/test/test-suite b/test/test-suite index f506024a..b4eddba7 100755 --- a/test/test-suite +++ b/test/test-suite @@ -1582,15 +1582,28 @@ class ParsingModeTests(AbstractQTestCase): class FormattingTests(AbstractQTestCase): def test_column_formatting(self): - cmd = 'seq 1 10 | ../bin/q -f 1=%4.3f,2=%4.3f "select sum(c1),avg(c1) from -"' + cmd = 'seq 1 10 | ../bin/q -f 1=%4.3f,2=%4.3f "select sum(c1),avg(c1) from -" -c 1' retcode, o, e = run_command(cmd) self.assertEquals(retcode, 0) self.assertEquals(len(o), 1) + self.assertEquals(len(e), 0) self.assertEquals(o[0], '55.000 5.500') + def test_column_formatting_with_output_header(self): + cmd = 'seq 1 10 | sed "1i column_name" | ../bin/q -f 1=%4.3f,2=%4.3f "select sum(column_name) mysum,avg(column_name) myavg from -" -c 1 -H -O' + + retcode, o, e = run_command(cmd) + + self.assertEquals(retcode, 0) + self.assertEquals(len(o), 2) + self.assertEquals(len(e), 0) + + self.assertEquals(o[0], 'mysum myavg') + self.assertEquals(o[1], '55.000 5.500') + class SqlTests(AbstractQTestCase):