{"action":"opened","issue":{"url":"https://api.github.com/repos/HazyResearch/deepdive/issues/488","repository_url":"https://api.github.com/repos/HazyResearch/deepdive","labels_url":"https://api.github.com/repos/HazyResearch/deepdive/issues/488/labels{/name}","comments_url":"https://api.github.com/repos/HazyResearch/deepdive/issues/488/comments","events_url":"https://api.github.com/repos/HazyResearch/deepdive/issues/488/events","html_url":"https://github.com/HazyResearch/deepdive/issues/488","id":133128682,"number":488,"title":"ddlog compiling to SQL with incorrect bracketing","user":{"login":"raphaelhoffmann","id":991789,"avatar_url":"https://avatars.githubusercontent.com/u/991789?v=3","gravatar_id":"","url":"https://api.github.com/users/raphaelhoffmann","html_url":"https://github.com/raphaelhoffmann","followers_url":"https://api.github.com/users/raphaelhoffmann/followers","following_url":"https://api.github.com/users/raphaelhoffmann/following{/other_user}","gists_url":"https://api.github.com/users/raphaelhoffmann/gists{/gist_id}","starred_url":"https://api.github.com/users/raphaelhoffmann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raphaelhoffmann/subscriptions","organizations_url":"https://api.github.com/users/raphaelhoffmann/orgs","repos_url":"https://api.github.com/users/raphaelhoffmann/repos","events_url":"https://api.github.com/users/raphaelhoffmann/events{/privacy}","received_events_url":"https://api.github.com/users/raphaelhoffmann/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-02-12T00:44:59Z","updated_at":"2016-02-12T00:44:59Z","closed_at":null,"body":"Consider the following ddlog example:\r\n```\r\nMultinomial(tag(word_id_1), tag(word_id_2)) :-\r\n  words(doc_id_1, sent_num_1, token_num_1, word_1, _, _, _, word_id_1),\r\n  words(doc_id_2, sent_num_2, token_num_2, word_2, _, _, _, word_id_2),\r\n  doc_id_1 = doc_id_2,\r\n  [sent_num_1 < sent_num_2; [sent_num_1 = sent_num_2, token_num_1 < token_num_2]],\r\n  [SUBSTR(word_1, 1, 1) != LOWER(SUBSTR(word_1, 1, 1))],\r\n  word_1 = word_2.\r\n```\r\nDDLOG compiler generates the following incorrect SQL:\r\n```\r\nSELECT R0.id AS \"tag.R0.id\" , R1.id AS \"tag.R1.id\"\r\nFROM tag R0, tag R1, words R2, words R3\r\nWHERE R2.word_id = R0.word_id  \r\nAND R3.word_id = R1.word_id  \r\nAND R2.doc_id = R3.doc_id \r\nAND R2.sent_num < R3.sent_num \r\nOR (R2.sent_num = R3.sent_num AND R2.token_num < R3.token_num) \r\nAND SUBSTR(R2.word, 1, 1) != LOWER(SUBSTR(R2.word, 1, 1)) \r\nAND R2.word = R3.word\r\n```\r\nThere should be parentheses around the `OR` condition, but I can't get these parentheses to appear. Is there some workaround?"}}