diff --git a/bin/q b/bin/q index b794ef34..c3b01828 100755 --- a/bin/q +++ b/bin/q @@ -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 c6d93440..38dc0ac4 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):