Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Relation parser fix #39

Merged
merged 6 commits into from
Nov 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/SqlSquared/Parser.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions test/src/Parse.purs
Original file line number Diff line number Diff line change
Expand Up @@ -927,3 +927,6 @@ testSuite6 = do
parseSucc Q.q19
parseSucc Q.q20
parseSucc Q.q21
parseSucc Q.q22
parseSucc Q.q23
parseSucc Q.q24
84 changes: 83 additions & 1 deletion test/src/Queries.purs
Original file line number Diff line number Diff line change
Expand Up @@ -680,4 +680,86 @@ group by
cntrycode
order by
cntrycode
"""
"""

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

)
"""