Skip to content

Commit

Permalink
Added proper error messages when having duplicate column names
Browse files Browse the repository at this point in the history
  • Loading branch information
harelba committed Apr 23, 2017
1 parent a81a493 commit ab509c7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
7 changes: 7 additions & 0 deletions bin/q
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
18 changes: 17 additions & 1 deletion test/test-suite
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -1727,7 +1744,6 @@ class FormattingTests(AbstractQTestCase):
self.cleanup(tmp_data_file)



class SqlTests(AbstractQTestCase):

def test_find_example(self):
Expand Down

0 comments on commit ab509c7

Please sign in to comment.