diff options
author | Harel Ben-Attia <harelba@gmail.com> | 2017-04-23 10:26:56 +0300 |
---|---|---|
committer | Harel Ben-Attia <harelba@gmail.com> | 2017-04-23 10:26:56 +0300 |
commit | ab509c7bcba8e2aa20cb9b3234124fabd39b7d30 (patch) | |
tree | 54ca5c98e7d109810dc0afa491319e6d308cacc0 | |
parent | a81a493bcee35177d5fbdb17e72209723bf91bb1 (diff) |
Added proper error messages when having duplicate column names
-rwxr-xr-x | bin/q | 7 | ||||
-rwxr-xr-x | test/test-suite | 18 |
2 files changed, 24 insertions, 1 deletions
@@ -525,6 +525,13 @@ class TableColumnInferer(object): column_name_errors.append( (v, "Column name must be UTF-8 Compatible")) continue + # We're checking for column duplication for each field in order to be able to still provide it along with other errors + if len(filter(lambda x: x == v,value_list)) > 1: + entry = (v, "Column name is duplicated") + # Don't duplicate the error report itself + if entry not in column_name_errors: + column_name_errors.append(entry) + continue nul_index = v.find("\x00") if nul_index >= 0: column_name_errors.append( diff --git a/test/test-suite b/test/test-suite index c6d9344..38dc0ac 100755 --- a/test/test-suite +++ b/test/test-suite @@ -1338,6 +1338,23 @@ class BasicTests(AbstractQTestCase): self.cleanup(tmpfile) + def test_duplicate_column_name_detection(self): + file_data = "a,b,a\n10,20,30\n30,40,50" + tmpfile = self.create_file_with_data(file_data) + + cmd = '../bin/q -H -d , "select a from %s"' % tmpfile.name + retcode, o, e = run_command(cmd) + + self.assertEquals(retcode, 35) + self.assertEquals(len(o), 0) + self.assertEquals(len(e), 2) + + self.assertTrue(e[0].startswith('Bad header row:')) + self.assertEquals(e[1],"'a': Column name is duplicated") + + self.cleanup(tmpfile) + + class ParsingModeTests(AbstractQTestCase): def test_strict_mode_column_count_mismatch_error(self): @@ -1727,7 +1744,6 @@ class FormattingTests(AbstractQTestCase): self.cleanup(tmp_data_file) - class SqlTests(AbstractQTestCase): def test_find_example(self): |