2 kyu

Simple SQL Engine

447 of 509SteveRuble
Description
Loading description...
SQL
Parsing
Sets
Databases
Algorithms
  • Please sign in or sign up to leave a comment.
  • ThatOneGuyWhoCodes Avatar

    Loved the Kata, interpereters are always fun, but I was able to brute force the random tests with a bit of good RNG.

    Now I gotta find something else to do......

  • Invariance Avatar

    I'm getting this error:

    Cannot read properties of undefined (reading 'replace')
    

    My code does pass the example tests fine; the issue is on the random tests. That said, I don't have a .replace in my code, so I'm not sure if this is my mistake or not. If it is, then the error message should be improved.

  • user6720290 Avatar

    Any tips on how to handle the quotes? Can't really wrap my head around them here.

  • rathesh77 Avatar

    Great kata even though some JS helpers should be forbidden to make it harder

  • davidmaamoaix Avatar

    The EBNF grammar is very off regarding the placements of whitespaces (Haskell).

  • DanielWeiner Avatar

    This comment has been hidden.

  • greenjaed Avatar

    The EBNF grammar definition in the kata is a little off. query includes join as [ ws, join ], but it's also included in the definition of from: [ { ws, join } ]. Seeing as the examples include a query with multiple joins, I believe the inclusion in query's definition is in error and should be removed.

  • sepi4 Avatar

    I like this kata. Took a while to complete it. Specially joins gave me a headache.

  • NoxLP Avatar

    I think I'm missing something. I have multiple problems with random tests, f.i. this SQL:

    select movie.directorid, actor.name, director.id FROM director JOIN movie on movie.directorID = director.id JOIN actor_to_movie on actor_to_movie.movieID = movie.id join actor on actor.id = actor_to_movie.actorID where director.name = 'Jon Favreau'
    

    The test expect an empty array as the result, but the database has movies with that director, and the SQL seems to have all the needed joins as far as I can tell. It could be I haven't used SQL in a long time, but I fail to see the problem here.

    PS: Btw, I forgot the test result: Expected: '[]', instead got: '[{ \'movie.directorid\': 5,\n \'actor.name\': \'Robert Downey Jr.\',\n \'director.id\': 5 }, { \'movie.directorid\': 5,\n \'actor.name\': \'Gwyneth Paltrow\',\n \'director.id\': 5 }, { \'movie.directorid\': 5,\n \'actor.name\': \'Terrence Howard\',\n \'director.id\': 5 }, { \'movie.directorid\': 5,\n \'actor.name\': \'Jeff Bridges\',\n \'director.id\': 5 }]'

  • DunetsNM Avatar

    It would benefit the kata if it was testing for malformed inputs too, getting the whitespace 100% correct with optional JOINs and WHERE in Parsec was surprisingly tricky (or maybe I was just tired).

  • GorVictor Avatar

    comparison = " = " | " > " | " < " | " <= " | " >= " | " <> " ; but in random tests for the comparison mask there are maybe no spaces

  • G_kuldeep Avatar

    cool one but not worthy of 2kyu

    edit: hey! anyone up for python translation??

  • ALowVerus Avatar

    In JS, console.log(query) responds with: SELECT movie.title FROM movie WHERE movie.title = 'Pirates of the Caribbean: Dead Man''s Chest'

    I imagine that those double single quotes constitute a mistake.

  • AyushBk Avatar

    This was one of the most enjoyable katas

  • JohanWiltink Avatar

    No solutions should have been harmed in upgrading this kata's Haskell version from 7.x to 8.x. We apologise for any inconvenience.

  • anhvut Avatar

    really really really fun kata. reminds me some compilation course at school. finally this was not so difficult. thanks all guys who contributed to this kata

  • dukies_2000 Avatar

    It's so nice to complete katas with some semblence of 'reality'. Thank you for this kata, I had a lot of fun with it!

  • Ibot02 Avatar

    Haskell random test queries are way more liberal on whitespace than the grammar (whitespace at beggining/end of query, arbitrary whitespace instead of a single space after "SELECT", "FROM" etc.).

    I would consider these bugs in the description rather than the test cases.

  • JohanWiltink Avatar

    Haskell translation

    Note that I have limited this translation to string values for simplicity. Haskell does not support mixing and matching Strings and Numbers.

    @SteveRuble, thank you for a great kata. Solving and translating it was a pleasure ( well, mostly :P ) and an honour.

  • metalim Avatar
  • Fr0st_P1xel Avatar

    This comment has been hidden.

  • docgunthrop Avatar

    @Steve Ruble, this kata should be ready for approval once you've implemented random tests. Nice job 👍

  • kesheshyan Avatar

    Excelent kata! Had a lot of fan and sleepless nights :) You've made a great job! I only need voice my concern about two single quotes that should be escaped as a single quote. I didn't know about that and a bit stuck trying to figure out what the heck is going on here. I should read kata description more carefuly next time... Anyways, thanks a lot for all the great work you're duing here!

  • Freywar Avatar

    Very good kata! It's always interesting to implement any kind of translators and with such detailed description it is pleasure. Hope one day you'll make level two with all excluded features and maybe level three which will check performance.

    Also it'd be nice if you add little more details in description:

    • explicit clarification that SQL is case insensitive. Also you might consider converting operators in your BNF into upper case - as far as I know it is most used case for SQL.
    • marking 'WHERE' section as optional in BNF.
    • clarification of what "valid table id" means.
  • wthit56 Avatar

    A very interesting kata. Always wanted to write on along these lines, so good on you for making it!

    There are a couple of things holding me back from making much progress:

    • The example test fixture tests don't work; an error says assertSimilarRows is not defined. I think the preloaded code doesn't get run when you run the ETF, unfortunately.
    • The working assertSimilarRows in the regular tests isn't very informative. actual did not contain the row at 0 in expected: {"title":"E.T. the Extra-Terrestrial"} to me implies this is being checked line-by-line, which could have the ordering problem assertSimilarRows was meant to solve. Also, it doesn't show what it got, only what it expected. For that first test, for example, I'm giving it the right results, but it appears to think they are incorrect. I don't know if the problem's my and or yours, but the error doesn't help me figure out how to proceed, as is.

    Looking forward to getting stuck in once more and seeing if my solution works ;P