-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed groupLimit functionality (#87)
This functionality was added in Laravel 11. MySQL driver checks the version of the database and if it is less than 8 then generates a query with unsupported syntax for UDV. It seems that functionality for MySQL >= 8 works well with SingleStore. Added test that checks this. --------- Co-authored-by: AdalbertMemSQL <[email protected]>
- Loading branch information
1 parent
8e6b5b4
commit d15a998
Showing
6 changed files
with
63 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace SingleStore\Laravel\Tests\Hybrid; | ||
|
||
use Illuminate\Foundation\Application; | ||
use Illuminate\Support\Facades\DB; | ||
use SingleStore\Laravel\Schema\Blueprint; | ||
use SingleStore\Laravel\Tests\BaseTest; | ||
|
||
class GroupLimitTest extends BaseTest | ||
{ | ||
use HybridTestHelpers; | ||
|
||
/** @test */ | ||
public function groupLimit() | ||
{ | ||
if (version_compare(Application::VERSION, '11.0.0', '<')) { | ||
// fulltext not added until later on in laravel 8 releases | ||
$this->markTestSkipped('requires higher laravel version'); | ||
|
||
return; | ||
} | ||
|
||
$query = DB::table('test')->orderBy('id')->groupLimit(2, 'group'); | ||
$this->assertEquals( | ||
'select * from (select *, row_number() over (partition by `group` order by `id` asc) as `laravel_row` from `test`) as `laravel_table` where `laravel_row` <= 2 order by `laravel_row`', | ||
$query->toSql() | ||
); | ||
|
||
if (! $this->runHybridIntegrations()) { | ||
return; | ||
} | ||
|
||
$this->createTable(function (Blueprint $table) { | ||
$table->id(); | ||
$table->integer('group'); | ||
}); | ||
|
||
DB::table('test')->insert([ | ||
['id' => 1, 'group' => 1], | ||
['id' => 2, 'group' => 1], | ||
['id' => 3, 'group' => 1], | ||
['id' => 4, 'group' => 2], | ||
['id' => 5, 'group' => 3], | ||
['id' => 6, 'group' => 3], | ||
['id' => 7, 'group' => 3], | ||
['id' => 8, 'group' => 3], | ||
]); | ||
|
||
$ids = $query->get(['id'])->pluck('id')->toArray(); | ||
sort($ids); | ||
$this->assertEquals($ids, [1, 2, 4, 5, 6]); | ||
} | ||
} |