From dfd765d6ee013409582e907602f8900b5f6fd986 Mon Sep 17 00:00:00 2001 From: Maxim Zimaliev Date: Tue, 21 Nov 2017 15:11:40 +0300 Subject: [PATCH] Relation parser fix (#39) * simpleRelation is parened relation case * removed redundant try * removed unneeded file * typo * less try's, parenRelation * moved try --- src/SqlSquared/Parser.purs | 11 ++++- test/src/Parse.purs | 3 ++ test/src/Queries.purs | 84 +++++++++++++++++++++++++++++++++++++- 3 files changed, 95 insertions(+), 3 deletions(-) diff --git a/src/SqlSquared/Parser.purs b/src/SqlSquared/Parser.purs index 4b06b58..436a2eb 100644 --- a/src/SqlSquared/Parser.purs +++ b/src/SqlSquared/Parser.purs @@ -558,7 +558,15 @@ simpleRelation ∷ ∀ m t. SqlParser m t (Sig.Relation t) simpleRelation = tableRelation <|> variRelation - <|> exprRelation + <|> PC.try exprRelation + <|> parenRelation + +parenRelation ∷ ∀ m t. SqlParser m t (Sig.Relation t) +parenRelation = do + _ ← operator "(" + r ← relation + _ ← operator ")" + pure r tableRelation ∷ ∀ m t. SqlParser m t (Sig.Relation t) tableRelation = do @@ -575,7 +583,6 @@ tableRelation = do ident pure $ Sig.TableRelation { alias: a, path } - variRelation ∷ ∀ m t. SqlParser m t (Sig.Relation t) variRelation = do vari ← variableString diff --git a/test/src/Parse.purs b/test/src/Parse.purs index a802c39..012e923 100644 --- a/test/src/Parse.purs +++ b/test/src/Parse.purs @@ -927,3 +927,6 @@ testSuite6 = do parseSucc Q.q19 parseSucc Q.q20 parseSucc Q.q21 + parseSucc Q.q22 + parseSucc Q.q23 + parseSucc Q.q24 diff --git a/test/src/Queries.purs b/test/src/Queries.purs index a1c79f9..7c923a6 100644 --- a/test/src/Queries.purs +++ b/test/src/Queries.purs @@ -680,4 +680,86 @@ group by cntrycode order by cntrycode -""" \ No newline at end of file +""" + +q22 ∷ String +q22 = """ +select clientdetails.name as name, clientdetails.surname as surname, clientdetails.email as email, +raw.txType as txType, raw.currency as currency, sum(raw.amount) as amount, count(raw.*) as cnt from +( + +select distinct +clientdetails.clientID as clientID, transactions.dateTime as dateTime, (transactions).amount as amount, (transactions).currency as currency, (transactions).txType as txType +from +`/ourcustomer/employeepositions` as employeepositions inner join +`/ourcustomer/locationpositions` as locationpositions on employeepositions.locPosID = locationpositions.`_id` inner join +`/ourcustomer/locations` as locations on locationpositions.locID = locations.`_id` inner join +`/ourcustomer/transactions` as transactions on transactions.clientID = employeepositions.clientID inner join +`/ourcustomer/clientdetails` as clientdetails on clientdetails.clientID = transactions.clientID +where locations.hideFromKpi <> true +and transactions.txType in (10, 20, 30, 40, 50, 60, 100, 110) +and transactions.dateTime >= "2017-10-01T00:00:00.000Z" +and transactions.dateTime < "2017-11-15T23:59:59.999Z" +) +as raw +inner join `/ourcustomer/clientdetails` as clientdetails on clientdetails.clientID = raw.clientID +group by clientdetails.email, clientdetails.name, clientdetails.surname, raw.txType, raw.currency +""" + +q23 ∷ String +q23 = """ +select distinct transactions.clientID, transactions.currency +from ( ( ( `/ourcustomer/employeepositions` as employeepositions inner join `/ourcustomer/locationpositions` as locationpositions on (((employeepositions).locPosID) = ((locationpositions).`_id`)) ) +inner join `/ourcustomer/locations` as locations on (((locationpositions).locID) = ((locations).`_id`)) ) +inner join `/ourcustomer/transactions` as transactions on (((transactions).clientID) = ((employeepositions).clientID)) ) +where (((locations).hideFromKpi) <> (true)) +and transactions.txType in (50,60,100,110) +and transactions.datenumber > 20170911 +""" + +q24 ∷ String +q24 = """ +select total.locations_name as `Location`, total.country as `Country`, +ip.amount as `OurCustomer Pay`, +pay.amount as `Balance of Pay`, +tips.amount as `Tips`, +dailyTips.amount as `Daily Tips`, +other.amount as `Other`, +total.amount as `Total` from + +( + +(SELECT sum(amount) as amount, country, locations_id, locations_name from `/work/view_mandeep` where dateTime >= :start and dateTime <= :end group by locations_id, locations_name, country) as total + +left join + +(SELECT sum(amount) as amount, locations_id from `/work/view_mandeep` where txType = 10 and dateTime >= :start and dateTime <= :end group by locations_id) as ip + +on total.locations_id = ip.locations_id + +left join + +(SELECT sum(amount) as amount, locations_id from `/work/view_mandeep` where txType = 20 and dateTime >= :start and dateTime <= :end group by locations_id) as pay + +on pay.locations_id = total.locations_id + +left join + +(SELECT sum(amount) as amount, locations_id from `/work/view_mandeep` where txType = 30 and payTipsDaily != true and dateTime >= :start and dateTime <= :end group by locations_id) as tips + +on tips.locations_id = total.locations_id + +left join + +(SELECT sum(amount) as amount, locations_id from `/work/view_mandeep` where txType = 30 and payTipsDaily = true and dateTime >= :start and dateTime <= :end group by locations_id) as dailyTips + +on dailyTips.locations_id = total.locations_id + +left join + +(SELECT sum(amount) as amount, locations_id from `/work/view_mandeep` where txType = 40 and dateTime >= :start and dateTime <= :end group by locations_id) as other + +on other.locations_id = total.locations_id + +) +"""