Skip to content
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

Regexes in nested queries do not work #754

Closed
SimonJF opened this issue Sep 17, 2019 · 2 comments · Fixed by #852
Closed

Regexes in nested queries do not work #754

SimonJF opened this issue Sep 17, 2019 · 2 comments · Fixed by #852
Assignees
Labels

Comments

@SimonJF
Copy link
Member

SimonJF commented Sep 17, 2019

Looking at the dictionary suggestion example, (examples/dictionary/dictSuggest.links), we can use regex syntax to translate to SQL LIKE predicates. However, this is unsupported when using nested queries.

MFE:

var db = database "test";

var testTable = table "testTable" with (field: String) from db;

query {
  for (x <-- testTable)
    where (x.field =~ /^{"foo"}.*/)
    [x]
}

yields

   (Query.Lang.Concat
      [(Query.Lang.Singleton
          (Query.Lang.Variant ("StartAnchor", (Query.Lang.Record {}))));
        (Query.Lang.Singleton
           (Query.Lang.Variant ("Quote",
              (Query.Lang.Variant ("Simply",
                 (Query.Lang.Constant (CommonTypes.Constant.String "foo"))))
              )));
        (Query.Lang.Singleton
           (Query.Lang.Variant ("Repeat",
              (Query.Lang.Record
                 {1 => (Query.Lang.Variant ("Star", (Query.Lang.Record {}))); 
                 2 => (Query.Lang.Variant ("Any", (Query.Lang.Record {}))); })
              )))
        ])
   ))
@SimonJF
Copy link
Member Author

SimonJF commented Sep 17, 2019

In the short term, I will unblock myself by implementing #538 as I'm not too familiar with the intricacies of the normalisation algorithm.

@jamescheney
Copy link
Contributor

This is a little surprising to me, since the query itself is flat, we should take a look. It may be a shallow problem, perhaps just due to not doing the regex translation when shredding is enabled.

@jamescheney jamescheney self-assigned this Jun 22, 2020
@jamescheney jamescheney mentioned this issue Jun 22, 2020
SimonJF pushed a commit that referenced this issue Jun 22, 2020
* fix 754 by passing regular expressions through let insertion and flattening stages

* whitespace

* whitespace

* add genuinely nested query test
jamescheney added a commit that referenced this issue Jun 22, 2020
* fix 754 by passing regular expressions through let insertion and flattening stages

* whitespace

* whitespace

* add genuinely nested query test
frank-emrich pushed a commit to frank-emrich/links that referenced this issue Sep 16, 2020
* fix 754 by passing regular expressions through let insertion and flattening stages

* whitespace

* whitespace

* add genuinely nested query test
SimonJF added a commit that referenced this issue Nov 19, 2020
…xpressions (#935)

# Issue

(Related in part to #754).

Previously, compiled regular expressions failed at runtime. As an example from GtoPdb:

```
for (strI <-- Tables.structural_info)
  where (strI.object_id == objectId && strI.species_id == 2)
  for (al <-- Tables.allele)
    where (strI.official_gene_id <> "" && al.accessions =~ /.*{strI.official_gene_id}.*/)
```

would fail due to the clause

```
al.accessions =~ /.*{strI.official_gene_id}.*/
```

within the `where` clause, since we're including a regular expression which projects from the `strI` table.

# Scope

This patch rectifies the above problem for `LIKE`-translatable queries (but not yet for arbitrary `RLIKE` queries).

# Proposal

To fix this, we need to do two things: generalise the return type of `likeify` to return a `base` expression which then allows strings, concatenation, and projection operators; and ensure the nested query translations occur inside regular expressions.

The patch also ensures that concatenation is translated correctly by the MySQL database driver.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants