@@ -17,6 +17,7 @@ func sampleForJoin() (*datatable.DataTable, *datatable.DataTable) {
1717 customers .AddColumn ("nom" , datatable .String )
1818 customers .AddColumn ("email" , datatable .String )
1919 customers .AddColumn ("ville" , datatable .String )
20+ // customers.AddColumn("concat", datatable.String, datatable.Expr("CONCAT(`prenom`,`nom`)"))
2021 customers .AppendRow (1 , "Aimée" , "Marechal" , "aime.marechal@example.com" , "Paris" )
2122 customers .AppendRow (2 , "Esmée" , "Lefort" , "esmee.lefort@example.com" , "Lyon" )
2223 customers .AppendRow (3 , "Marine" , "Prevost" , "m.prevost@example.com" , "Lille" )
@@ -59,17 +60,16 @@ func TestJoinOn(t *testing.T) {
5960
6061func TestInnerJoin (t * testing.T ) {
6162 customers , orders := sampleForJoin ()
62-
63+ customers . AddColumn ( "concat" , datatable . String , datatable . Expr ( "concat(`prenom`, `nom`)" ))
6364 dt , err := customers .InnerJoin (orders , datatable .On ("[Customers].[id]" , "[Orders].[user_id]" ))
6465 assert .NoError (t , err )
6566 assert .NotNil (t , dt )
66-
6767 checkTable (t , dt ,
68- "id" , "prenom" , "nom" , "email" , "ville" , "date_achat" , "num_facture" , "prix_total" ,
69- 1 , "Aimée" , "Marechal" , "aime.marechal@example.com" , "Paris" , time .Date (2013 , time .January , 23 , 0 , 0 , 0 , 0 , time .UTC ), "A00103" , 203.14 ,
70- 1 , "Aimée" , "Marechal" , "aime.marechal@example.com" , "Paris" , time .Date (2013 , time .February , 14 , 0 , 0 , 0 , 0 , time .UTC ), "A00104" , 124.00 ,
71- 2 , "Esmée" , "Lefort" , "esmee.lefort@example.com" , "Lyon" , time .Date (2013 , time .February , 17 , 0 , 0 , 0 , 0 , time .UTC ), "A00105" , 149.45 ,
72- 3 , "Marine" , "Prevost" , "m.prevost@example.com" , "Lille" , time .Date (2013 , time .February , 21 , 0 , 0 , 0 , 0 , time .UTC ), "A00106" , 235.35 ,
68+ "id" , "prenom" , "nom" , "email" , "ville" , "concat" , " date_achat" , "num_facture" , "prix_total" ,
69+ 1 , "Aimée" , "Marechal" , "aime.marechal@example.com" , "Paris" , "AiméeMarechal" , time .Date (2013 , time .January , 23 , 0 , 0 , 0 , 0 , time .UTC ), "A00103" , 203.14 ,
70+ 1 , "Aimée" , "Marechal" , "aime.marechal@example.com" , "Paris" , "AiméeMarechal" , time .Date (2013 , time .February , 14 , 0 , 0 , 0 , 0 , time .UTC ), "A00104" , 124.00 ,
71+ 2 , "Esmée" , "Lefort" , "esmee.lefort@example.com" , "Lyon" , "EsméeLefort" , time .Date (2013 , time .February , 17 , 0 , 0 , 0 , 0 , time .UTC ), "A00105" , 149.45 ,
72+ 3 , "Marine" , "Prevost" , "m.prevost@example.com" , "Lille" , "MarinePrevost" , time .Date (2013 , time .February , 21 , 0 , 0 , 0 , 0 , time .UTC ), "A00106" , 235.35 ,
7373 )
7474}
7575
@@ -125,27 +125,63 @@ func TestOuterJoin(t *testing.T) {
125125 )
126126}
127127
128- func TestJoinWithExpr (t * testing.T ) {
128+ func TestInnerJoinWithExprOnHidden (t * testing.T ) {
129129 customers , orders := sampleForJoin ()
130- customers .AddColumn ("upper_ville" , datatable .String , datatable .Expr ("UPPER(ville)" ))
130+ customers .AddColumn ("id2" , datatable .Int , datatable .Expr ("`id`+100" ))
131+ orders .AddColumn ("user_id2" , datatable .Int , datatable .Expr ("`user_id`+100" ))
132+ customers .HideColumn ("id" )
133+ dt , err := customers .InnerJoin (orders , datatable .On ("[Customers].[id2]" , "[Orders].[user_id2]" ))
134+ assert .NoError (t , err )
135+ assert .NotNil (t , dt )
131136
132- dt , err := customers .InnerJoin (orders , datatable .On ("[Customers].[id]" , "[Orders].[user_id]" ))
137+ fmt .Println (dt )
138+
139+ checkTable (t , dt ,
140+ "prenom" , "nom" , "email" , "ville" , "id2" , "user_id" , "date_achat" , "num_facture" , "prix_total" ,
141+ "Aimée" , "Marechal" , "aime.marechal@example.com" , "Paris" , 101 , 1 , time .Date (2013 , time .January , 23 , 0 , 0 , 0 , 0 , time .UTC ), "A00103" , 203.14 ,
142+ "Aimée" , "Marechal" , "aime.marechal@example.com" , "Paris" , 101 , 1 , time .Date (2013 , time .February , 14 , 0 , 0 , 0 , 0 , time .UTC ), "A00104" , 124.00 ,
143+ "Esmée" , "Lefort" , "esmee.lefort@example.com" , "Lyon" , 102 , 2 , time .Date (2013 , time .February , 17 , 0 , 0 , 0 , 0 , time .UTC ), "A00105" , 149.45 ,
144+ "Marine" , "Prevost" , "m.prevost@example.com" , "Lille" , 103 , 3 , time .Date (2013 , time .February , 21 , 0 , 0 , 0 , 0 , time .UTC ), "A00106" , 235.35 ,
145+ )
146+ }
147+
148+ func TestLeftJoinWithExpr (t * testing.T ) {
149+ customers , orders := sampleForJoin ()
150+ customers .AddColumn ("id2" , datatable .Int , datatable .Expr ("`id`+100" ))
151+ orders .AddColumn ("user_id2" , datatable .Int , datatable .Expr ("`user_id`+100" ))
152+ dt , err := customers .LeftJoin (orders , datatable .On ("[Customers].[id2]" , "[Orders].[user_id2]" ))
133153 assert .NoError (t , err )
134154 assert .NotNil (t , dt )
135155
136- col := dt .Column ("upper_ville" )
137- assert .Equal (t , datatable .String , col .Type ())
138- assert .Equal (t , "NullString" , col .UnderlyingType ().Name ())
139- assert .True (t , col .IsComputed ())
156+ fmt .Println (dt )
157+
158+ checkTable (t , dt ,
159+ "id" , "prenom" , "nom" , "email" , "ville" , "id2" , "user_id" , "date_achat" , "num_facture" , "prix_total" ,
160+ 1 , "Aimée" , "Marechal" , "aime.marechal@example.com" , "Paris" , 101 , 1 , time .Date (2013 , time .January , 23 , 0 , 0 , 0 , 0 , time .UTC ), "A00103" , 203.14 ,
161+ 1 , "Aimée" , "Marechal" , "aime.marechal@example.com" , "Paris" , 101 , 1 , time .Date (2013 , time .February , 14 , 0 , 0 , 0 , 0 , time .UTC ), "A00104" , 124.00 ,
162+ 2 , "Esmée" , "Lefort" , "esmee.lefort@example.com" , "Lyon" , 102 , 2 , time .Date (2013 , time .February , 17 , 0 , 0 , 0 , 0 , time .UTC ), "A00105" , 149.45 ,
163+ 3 , "Marine" , "Prevost" , "m.prevost@example.com" , "Lille" , 103 , 3 , time .Date (2013 , time .February , 21 , 0 , 0 , 0 , 0 , time .UTC ), "A00106" , 235.35 ,
164+ 4 , "Luc" , "Rolland" , "lucrolland@example.com" , "Marseille" , 104 , nil , nil , nil , nil ,
165+ )
166+ }
167+
168+ func TestRightJoinWithExpr (t * testing.T ) {
169+ customers , orders := sampleForJoin ()
170+ customers .AddColumn ("id2" , datatable .Int , datatable .Expr ("`id`+100" ))
171+ orders .AddColumn ("user_id2" , datatable .Int , datatable .Expr ("`user_id`+100" ))
172+ dt , err := customers .RightJoin (orders , datatable .On ("[Customers].[id2]" , "[Orders].[user_id2]" ))
173+ assert .NoError (t , err )
174+ assert .NotNil (t , dt )
140175
141176 fmt .Println (dt )
142177
143178 checkTable (t , dt ,
144- "id" , "prenom" , "nom" , "email" , "ville" , "upper_ville" , "date_achat" , "num_facture" , "prix_total" ,
145- 1 , "Aimée" , "Marechal" , "aime.marechal@example.com" , "Paris" , "PARIS" , time .Date (2013 , time .January , 23 , 0 , 0 , 0 , 0 , time .UTC ), "A00103" , 203.14 ,
146- 1 , "Aimée" , "Marechal" , "aime.marechal@example.com" , "Paris" , "PARIS" , time .Date (2013 , time .February , 14 , 0 , 0 , 0 , 0 , time .UTC ), "A00104" , 124.00 ,
147- 2 , "Esmée" , "Lefort" , "esmee.lefort@example.com" , "Lyon" , "LYON" , time .Date (2013 , time .February , 17 , 0 , 0 , 0 , 0 , time .UTC ), "A00105" , 149.45 ,
148- 3 , "Marine" , "Prevost" , "m.prevost@example.com" , "Lille" , "LILLE" , time .Date (2013 , time .February , 21 , 0 , 0 , 0 , 0 , time .UTC ), "A00106" , 235.35 ,
179+ "id" , "prenom" , "nom" , "email" , "ville" , "id2" , "user_id" , "date_achat" , "num_facture" , "prix_total" ,
180+ 1 , "Aimée" , "Marechal" , "aime.marechal@example.com" , "Paris" , 101 , 1 , time .Date (2013 , time .January , 23 , 0 , 0 , 0 , 0 , time .UTC ), "A00103" , 203.14 ,
181+ 1 , "Aimée" , "Marechal" , "aime.marechal@example.com" , "Paris" , 101 , 1 , time .Date (2013 , time .February , 14 , 0 , 0 , 0 , 0 , time .UTC ), "A00104" , 124.00 ,
182+ 2 , "Esmée" , "Lefort" , "esmee.lefort@example.com" , "Lyon" , 102 , 2 , time .Date (2013 , time .February , 17 , 0 , 0 , 0 , 0 , time .UTC ), "A00105" , 149.45 ,
183+ 3 , "Marine" , "Prevost" , "m.prevost@example.com" , "Lille" , 103 , 3 , time .Date (2013 , time .February , 21 , 0 , 0 , 0 , 0 , time .UTC ), "A00106" , 235.35 ,
184+ nil , nil , nil , nil , nil , nil , 5 , time .Date (2013 , time .March , 2 , 0 , 0 , 0 , 0 , time .UTC ), "A00107" , 47.58 ,
149185 )
150186}
151187
0 commit comments