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

Commit dfd765d

Browse files
authored
Relation parser fix (#39)
* simpleRelation is parened relation case * removed redundant try * removed unneeded file * typo * less try's, parenRelation * moved try
1 parent 976e79e commit dfd765d

File tree

3 files changed

+95
-3
lines changed

3 files changed

+95
-3
lines changed

src/SqlSquared/Parser.purs

+9-2
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,15 @@ simpleRelation ∷ ∀ m t. SqlParser m t (Sig.Relation t)
558558
simpleRelation =
559559
tableRelation
560560
<|> variRelation
561-
<|> exprRelation
561+
<|> PC.try exprRelation
562+
<|> parenRelation
563+
564+
parenRelation m t. SqlParser m t (Sig.Relation t)
565+
parenRelation = do
566+
_ ← operator "("
567+
r ← relation
568+
_ ← operator ")"
569+
pure r
562570

563571
tableRelation m t. SqlParser m t (Sig.Relation t)
564572
tableRelation = do
@@ -575,7 +583,6 @@ tableRelation = do
575583
ident
576584
pure $ Sig.TableRelation { alias: a, path }
577585

578-
579586
variRelation m t. SqlParser m t (Sig.Relation t)
580587
variRelation = do
581588
vari ← variableString

test/src/Parse.purs

+3
Original file line numberDiff line numberDiff line change
@@ -927,3 +927,6 @@ testSuite6 = do
927927
parseSucc Q.q19
928928
parseSucc Q.q20
929929
parseSucc Q.q21
930+
parseSucc Q.q22
931+
parseSucc Q.q23
932+
parseSucc Q.q24

test/src/Queries.purs

+83-1
Original file line numberDiff line numberDiff line change
@@ -680,4 +680,86 @@ group by
680680
cntrycode
681681
order by
682682
cntrycode
683-
"""
683+
"""
684+
685+
q22 String
686+
q22 = """
687+
select clientdetails.name as name, clientdetails.surname as surname, clientdetails.email as email,
688+
raw.txType as txType, raw.currency as currency, sum(raw.amount) as amount, count(raw.*) as cnt from
689+
(
690+
691+
select distinct
692+
clientdetails.clientID as clientID, transactions.dateTime as dateTime, (transactions).amount as amount, (transactions).currency as currency, (transactions).txType as txType
693+
from
694+
`/ourcustomer/employeepositions` as employeepositions inner join
695+
`/ourcustomer/locationpositions` as locationpositions on employeepositions.locPosID = locationpositions.`_id` inner join
696+
`/ourcustomer/locations` as locations on locationpositions.locID = locations.`_id` inner join
697+
`/ourcustomer/transactions` as transactions on transactions.clientID = employeepositions.clientID inner join
698+
`/ourcustomer/clientdetails` as clientdetails on clientdetails.clientID = transactions.clientID
699+
where locations.hideFromKpi <> true
700+
and transactions.txType in (10, 20, 30, 40, 50, 60, 100, 110)
701+
and transactions.dateTime >= "2017-10-01T00:00:00.000Z"
702+
and transactions.dateTime < "2017-11-15T23:59:59.999Z"
703+
)
704+
as raw
705+
inner join `/ourcustomer/clientdetails` as clientdetails on clientdetails.clientID = raw.clientID
706+
group by clientdetails.email, clientdetails.name, clientdetails.surname, raw.txType, raw.currency
707+
"""
708+
709+
q23 String
710+
q23 = """
711+
select distinct transactions.clientID, transactions.currency
712+
from ( ( ( `/ourcustomer/employeepositions` as employeepositions inner join `/ourcustomer/locationpositions` as locationpositions on (((employeepositions).locPosID) = ((locationpositions).`_id`)) )
713+
inner join `/ourcustomer/locations` as locations on (((locationpositions).locID) = ((locations).`_id`)) )
714+
inner join `/ourcustomer/transactions` as transactions on (((transactions).clientID) = ((employeepositions).clientID)) )
715+
where (((locations).hideFromKpi) <> (true))
716+
and transactions.txType in (50,60,100,110)
717+
and transactions.datenumber > 20170911
718+
"""
719+
720+
q24 String
721+
q24 = """
722+
select total.locations_name as `Location`, total.country as `Country`,
723+
ip.amount as `OurCustomer Pay`,
724+
pay.amount as `Balance of Pay`,
725+
tips.amount as `Tips`,
726+
dailyTips.amount as `Daily Tips`,
727+
other.amount as `Other`,
728+
total.amount as `Total` from
729+
730+
(
731+
732+
(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
733+
734+
left join
735+
736+
(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
737+
738+
on total.locations_id = ip.locations_id
739+
740+
left join
741+
742+
(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
743+
744+
on pay.locations_id = total.locations_id
745+
746+
left join
747+
748+
(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
749+
750+
on tips.locations_id = total.locations_id
751+
752+
left join
753+
754+
(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
755+
756+
on dailyTips.locations_id = total.locations_id
757+
758+
left join
759+
760+
(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
761+
762+
on other.locations_id = total.locations_id
763+
764+
)
765+
"""

0 commit comments

Comments
 (0)