Skip to content

Join using instead on db issues #1126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Reverting the comment from @squirrelo on search for JOIN...ON -> USIN…
…G cause it currently breaks
  • Loading branch information
josenavas committed Apr 29, 2015
commit a546233f1af8b43458aab65a63c302a6224c066f
4 changes: 2 additions & 2 deletions qiita_db/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,8 @@ def _parse_study_search_string(self, searchstr,

sample_sql = ("SELECT ss.sample_id,%s "
"FROM qiita.study_sample ss "
"JOIN qiita.sample_{0} sa USING (sample_id) "
"JOIN qiita.study st USING (study_id) "
"JOIN qiita.sample_{0} sa ON ss.sample_id = sa.sample_id"
" JOIN qiita.study st ON st.study_id = ss.study_id "
"WHERE %s" %
(','.join(header_info), sql_where))
return study_sql, sample_sql, meta_header_type_lookup.keys()
Expand Down
35 changes: 21 additions & 14 deletions qiita_db/test/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ def test_parse_study_search_string(self):
"in ('integer', 'float8')")
exp_samp_sql = ("SELECT ss.sample_id,sa.altitude "
"FROM qiita.study_sample ss "
"JOIN qiita.sample_{0} sa USING (sample_id) "
"JOIN qiita.study st USING (study_id) "
"JOIN qiita.sample_{0} sa "
"ON ss.sample_id = sa.sample_id "
"JOIN qiita.study st ON st.study_id = ss.study_id "
"WHERE sa.altitude > 0")
self.assertEqual(st_sql, exp_st_sql)
self.assertEqual(samp_sql, exp_samp_sql)
Expand All @@ -44,8 +45,9 @@ def test_parse_study_search_string(self):
"in ('integer', 'float8')")
exp_samp_sql = ("SELECT ss.sample_id,sa.altitude "
"FROM qiita.study_sample ss "
"JOIN qiita.sample_{0} sa USING (sample_id) "
"JOIN qiita.study st USING (study_id) "
"JOIN qiita.sample_{0} sa "
"ON ss.sample_id = sa.sample_id "
"JOIN qiita.study st ON st.study_id = ss.study_id "
"WHERE NOT sa.altitude > 0")
self.assertEqual(st_sql, exp_st_sql)
self.assertEqual(samp_sql, exp_samp_sql)
Expand All @@ -59,8 +61,9 @@ def test_parse_study_search_string(self):
"('integer', 'float8')")
exp_samp_sql = ("SELECT ss.sample_id,sa.ph "
"FROM qiita.study_sample ss "
"JOIN qiita.sample_{0} sa USING (sample_id) "
"JOIN qiita.study st USING (study_id) "
"JOIN qiita.sample_{0} sa "
"ON ss.sample_id = sa.sample_id "
"JOIN qiita.study st ON st.study_id = ss.study_id "
"WHERE (sa.ph > 7 AND sa.ph < 9)")
self.assertEqual(st_sql, exp_st_sql)
self.assertEqual(samp_sql, exp_samp_sql)
Expand All @@ -74,8 +77,9 @@ def test_parse_study_search_string(self):
"('integer', 'float8')")
exp_samp_sql = ("SELECT ss.sample_id,sa.ph "
"FROM qiita.study_sample ss "
"JOIN qiita.sample_{0} sa USING (sample_id) "
"JOIN qiita.study st USING (study_id) "
"JOIN qiita.sample_{0} sa "
"ON ss.sample_id = sa.sample_id "
"JOIN qiita.study st ON st.study_id = ss.study_id "
"WHERE (sa.ph > 7 OR sa.ph < 9)")
self.assertEqual(st_sql, exp_st_sql)
self.assertEqual(samp_sql, exp_samp_sql)
Expand All @@ -90,8 +94,9 @@ def test_parse_study_search_string(self):
"and column_type in ('varchar')")
exp_samp_sql = ("SELECT ss.sample_id,sa.host_subject_id "
"FROM qiita.study_sample ss "
"JOIN qiita.sample_{0} sa USING (sample_id) "
"JOIN qiita.study st USING (study_id) "
"JOIN qiita.sample_{0} sa "
"ON ss.sample_id = sa.sample_id "
"JOIN qiita.study st ON st.study_id = ss.study_id "
"WHERE LOWER(sa.host_subject_id) "
"LIKE '%chicken little%'")
self.assertEqual(st_sql, exp_st_sql)
Expand All @@ -110,8 +115,9 @@ def test_parse_study_search_string(self):
exp_samp_sql = (
"SELECT ss.sample_id,sa.name "
"FROM qiita.study_sample ss "
"JOIN qiita.sample_{0} sa USING (sample_id) "
"JOIN qiita.study st USING (study_id) "
"JOIN qiita.sample_{0} sa "
"ON ss.sample_id = sa.sample_id "
"JOIN qiita.study st ON st.study_id = ss.study_id "
"WHERE (sa.name = 'Billy Bob' OR sa.name = 'Timmy' OR "
"(sa.name = 'Jimbo' AND sa.name > 25) OR sa.name < 5)")
self.assertEqual(st_sql, exp_st_sql)
Expand All @@ -131,8 +137,9 @@ def test_parse_study_search_string(self):
"lower('ph') and column_type in ('integer', 'float8')"]
exp_samp_sql = ("SELECT ss.sample_id,sa.pH,sa.ph "
"FROM qiita.study_sample ss "
"JOIN qiita.sample_{0} sa USING (sample_id) "
"JOIN qiita.study st USING (study_id) "
"JOIN qiita.sample_{0} sa "
"ON ss.sample_id = sa.sample_id "
"JOIN qiita.study st ON st.study_id = ss.study_id "
"WHERE (sa.ph > 7 OR sa.ph < 9)")
# use the split list to make sure the SQL is properly formed
self.assertEqual(len(st_sql), 2)
Expand Down