2 kyu
Simple SQL Engine
447 of 509SteveRuble
Loading description...
SQL
Parsing
Sets
Databases
Algorithms
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
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......
I'm getting this error:
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.Any tips on how to handle the quotes? Can't really wrap my head around them here.
Great kata even though some JS helpers should be forbidden to make it harder
The EBNF grammar is very off regarding the placements of whitespaces (Haskell).
This comment has been hidden.
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 offrom
:[ { ws, join } ]
. Seeing as the examples include a query with multiple joins, I believe the inclusion inquery
's definition is in error and should be removed.I like this kata. Took a while to complete it. Specially joins gave me a headache.
I think I'm missing something. I have multiple problems with random tests, f.i. this SQL:
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 }]'
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).
comparison = " = " | " > " | " < " | " <= " | " >= " | " <> " ; but in random tests for the comparison mask there are maybe no spaces
In the Haskell Sample Test "should perform many-to-many JOIN and apply WHERE" a comparison without spaces is present. The EBNF-scheme therefor is not exactly correct, but imho this is not a big problem.
cool one but not worthy of 2kyu
edit: hey! anyone up for python translation??
would require to forbid some stuff...
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.
Apostrophes are used to escape apostrophes inside strings in SQL.
I haven't solved the kata, so I'm not closing the issue (just in case) but it looks like everything's alright.
Huh. The more you know. Gracias!
This was one of the most enjoyable katas
No solutions should have been harmed in upgrading this kata's Haskell version from 7.x to 8.x. We apologise for any inconvenience.
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
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!
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.
Haskell translation
Note that I have limited this translation to string values for simplicity. Haskell does not support mixing and matching
String
s andNumber
s.@SteveRuble, thank you for a great kata. Solving and translating it was a pleasure ( well, mostly :P ) and an honour.
Bump.
OP has been gone for months, so a mod may want to approve this.
Approved.
Thanks!
Coffeescript translation
.
This comment has been hidden.
That's not an issue, that's a question.
The descriptions says:
@Steve Ruble, this kata should be ready for approval once you've implemented random tests. Nice job 👍
Seeing as how the author has been inactive this month, I went ahead and made updates to this kata.
Added 30 random tests:
A number of submitted solutions have been invalidated with the addition of random testing. I've checked each of them and found that most of them legitimately fail, while some others pass (the majority of the time). The failure appears to be occurring mostly due to the way a solution handles the return of an empty array. This typically happens when none of the results adhere to the conditions of the
WHERE
clause (when one is given). Due to the randomness of the tests, these types of cases may occur, but are not guaranteed to occur.This kata is now approved.
This comment has been hidden.
@joh_pot
That's one of the pre-defined tests, correct? Your issue may have to do with how quotes are being handled. Per the description:Hopefully this helps.
Hey! Thanks for your quick reply! Yes, it is one of the predefined tests, so not the ones in the Example test section. I'm just confused by
movie.title = 'Pirates of the Caribbean: Dead Man''s Chest'
and then the data inmovieDatabase
is{ id: 13,title: 'Pirates of the Caribbean: Dead Man\'s Chest',year: 2006,directorID: 9 }
Those cannot match up because only the row in db has a single quote in the title but the query is looking for double single quotes, as in
'Pirates of the Caribbean: Dead Man''s Chest'
Aaah, now I see in description
and escaping internal single quotes by doubling them
. Thanks for your time mate.Ah, there it is. It's been a while since having visited this kata, but it was certainly something to do with the quotations marks. Glad to hear it's resolved.
Hi @docgunthrop
I have passed all the tests but then I get a final error right at the bottom after passing the randomized tests for my enjoyment with:
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
. --> To me this looks like a stackoverflow error, so it might be in my code where I'm sitting in an infinite loop. I don't know why it would cause an infinite loop if all the tests are completed?Any idea why this would happen? I can't
console.log
anything to see what the query could be.CW was experiencing some issues around the time that you posted your comment; give it another try and see if your solution goes through this time.
I found that the issue was I was using
JSON.parse()
on a huge object and that caused the memory issue. I have removed it and could submit my solution. Thanks for getting back to me and contributing to this excellent kata.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!
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:
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:
example test fixture
tests don't work; an error saysassertSimilarRows
is not defined. I think thepreloaded
code doesn't get run when you run theETF
, unfortunately.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 problemassertSimilarRows
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
preloaded
code wasn't available in the example tests. I've added the function to the example tests now.Hope that resolves your issues. Glad you like the kata.
Cool cool. Made it through, now. Just need to rewrite, refactor, and make it not horrendous and I'll submit it ;P
One tiny point... the error messages do give enough information to go on now, though
expected rows contain a row which does not exist in the actual rows
sounds really weird. I expected the message to tell me what I did wrong, what I left out, not what the expected table had extra than what I returned. So something likeyou left out these rows
would be easier to understand thanthese rows were expected to be there
. Do you know what I mean?OK, I've updated the messages so now it'll tell you what you're missing if you're missing a row, and tell you what you had extra if you had too many rows. Think that'll work?
Yeah, I'm sure that's fine. I've refactored my code and submitted the solution, now. So proud of myself! ^^
I forgot to say-- you should really explain all the terms and how they should work and interact. This is a complex subject for a newbie, so a brief explanation of the basics will really help.
I added some links to tutorials on the keywords to make it easier for people whose SQL is rusty or minimal, but I feel that this kata would be pretty difficult for a "newbie" no matter how much information I added to the description. Unless you think there's something which is unclear or confusing, or have specific content you think I should add, I think I'll leave it as is.
Yeah... I kinda meant new to SQL, not JS. But it's fair enough. It could be a fair bit of work to write such a tutorial.
I'd add a link to the EBNF mention. It's very useful if you know how to read an EBNF, but pretty cryptic if you're not up to speed.
As for the explanation, I enjoy writing this kind of stuff, so I thought I'd have a go at it. (This has now been added to the kata description.)
Wow, that's great. I've added that to the kata and credited you. Thanks for helping make this kata a lot better!
So happy to help ;P I was thinking of removing the explanation from the comment, just to save space for people looking for help and such. What do you think?
Yeah, I guess it's redundent to have it in a comment too. Thanks again for writing that up, though.
Cool. My pleasure. ^^
By the way, I'd love to see an "Advanced" version of this. There's another kata that tried to do something similar, which included more features, but the way it wanted you to do things was pretty wonky and frustrating, unfortunately. But the way you put this together, and what format you expect the results in is intuitive and not that hard to get your head around. I'd love to sink my teeth into expanding my implementation! ;P
Yeah, I'm planning on making a more advanced version. I'm thinking that will include AND and OR in the WHERE clause, GROUP BY, ORDER BY, and HAVING. Think that'll be advanced enough? (I considered including wildcards and aliases, but I feel like that would just add complexity without making it more interesting. What do you think?)
You could have an intermediate kata with AND, OR, GROUP BY, ORDER BY and HAVING. Then an advanced kata with wildcards, AS, and maybe even nested SQL (
SELECT numbers.n FROM (SELECT (table.number + 1) AS n FROM numbers) AS numbers
).As for me this is very simple kata (when I read requirements for each kyu I choosed 4 kyu). And this is very-very interestingkata. And I want intermediate version of kata (with allmost all support of SQL Select version). And I want advanced version of this Kata with support of INSERT/UPDATE and table indexes (so code that doesn't uses indexes will got timeout).
Thanks for kata!