jenkins-bot has submitted this change and it was merged.
Change subject: Have DescriptionMatchFinder return instances of EntityId rather
then internal ids.
......................................................................
Have DescriptionMatchFinder return instances of EntityId rather then internal
ids.
Change-Id: Ibc104d0545e12ac5f6dfe31014056087db278e44
---
M src/SQLStore/Engine/DescriptionMatchFinder.php
M src/SQLStore/Factory.php
M tests/integration/SQLStore/Engine/DescriptionMatchFinderIntegrationTest.php
M tests/integration/SQLStore/WritingIntegrationTest.php
M tests/phpunit/SQLStore/Engine/DescriptionMatchFinderTest.php
5 files changed, 42 insertions(+), 18 deletions(-)
Approvals:
Denny Vrandecic: Looks good to me, approved
jenkins-bot: Verified
diff --git a/src/SQLStore/Engine/DescriptionMatchFinder.php
b/src/SQLStore/Engine/DescriptionMatchFinder.php
index a61a48e..5a26448 100644
--- a/src/SQLStore/Engine/DescriptionMatchFinder.php
+++ b/src/SQLStore/Engine/DescriptionMatchFinder.php
@@ -14,6 +14,7 @@
use Wikibase\QueryEngine\QueryNotSupportedException;
use Wikibase\QueryEngine\SQLStore\DataValueHandler;
use Wikibase\QueryEngine\SQLStore\InternalEntityIdFinder;
+use Wikibase\QueryEngine\SQLStore\InternalEntityIdInterpreter;
use Wikibase\QueryEngine\SQLStore\Schema;
use Wikibase\SnakRole;
@@ -34,29 +35,31 @@
protected $schema;
protected $propertyDataValueTypeLookup;
protected $idFinder;
+ protected $idInterpreter;
public function __construct( QueryInterface $queryInterface,
Schema $schema,
PropertyDataValueTypeLookup
$propertyDataValueTypeLookup,
- InternalEntityIdFinder $idFinder ) {
+ InternalEntityIdFinder $idFinder,
+ InternalEntityIdInterpreter $idInterpreter ) {
+
$this->queryInterface = $queryInterface;
$this->schema = $schema;
$this->propertyDataValueTypeLookup =
$propertyDataValueTypeLookup;
$this->idFinder = $idFinder;
+ $this->idInterpreter = $idInterpreter;
}
/**
* Finds all entities that match the selection criteria.
* The matching entities are returned as an array of internal entity
ids.
*
- * TODO: return array of EntityId
- *
* @since 0.1
*
* @param Description $description
* @param QueryOptions $options
*
- * @return int[]
+ * @return EntityId[]
* @throws QueryNotSupportedException
*/
public function findMatchingEntities( Description $description,
QueryOptions $options ) {
@@ -95,7 +98,7 @@
$entityIds = array();
foreach ( $selectionResult as $resultRow ) {
- $entityIds[] = (int)$resultRow->subject_id;
+ $entityIds[] =
$this->idInterpreter->getExternalIdForEntity( (int)$resultRow->subject_id );
}
return $entityIds;
diff --git a/src/SQLStore/Factory.php b/src/SQLStore/Factory.php
index 20e2522..64cfa61 100644
--- a/src/SQLStore/Factory.php
+++ b/src/SQLStore/Factory.php
@@ -141,6 +141,13 @@
return new EntityIdTransformer(
$this->config->getEntityTypeMap() );
}
+ /**
+ * @return InternalEntityIdInterpreter
+ */
+ protected function getInternalEntityIdInterpreter() {
+ return new EntityIdTransformer(
$this->config->getEntityTypeMap() );
+ }
+
public function newWriter() {
return new Writer(
$this->newEntityInserter(),
@@ -157,7 +164,8 @@
$this->queryInterface,
$this->getSchema(),
$this->config->getPropertyDataValueTypeLookup(),
- $this->getInternalEntityIdFinder()
+ $this->getInternalEntityIdFinder(),
+ $this->getInternalEntityIdInterpreter()
);
}
diff --git
a/tests/integration/SQLStore/Engine/DescriptionMatchFinderIntegrationTest.php
b/tests/integration/SQLStore/Engine/DescriptionMatchFinderIntegrationTest.php
index fb763ff..56f47da 100644
---
a/tests/integration/SQLStore/Engine/DescriptionMatchFinderIntegrationTest.php
+++
b/tests/integration/SQLStore/Engine/DescriptionMatchFinderIntegrationTest.php
@@ -11,6 +11,7 @@
use Wikibase\Database\MediaWikiQueryInterface;
use Wikibase\Database\MessageReporter;
use Wikibase\Database\MWDB\ExtendedMySQLAbstraction;
+use Wikibase\Database\MWDB\ExtendedSQLiteAbstraction;
use Wikibase\Database\TableDefinition;
use Wikibase\EntityId;
use Wikibase\Item;
@@ -64,6 +65,7 @@
protected function newStore() {
$dbConnectionProvider = new LazyDBConnectionProvider( DB_MASTER
);
+ // TODO: use factory in DB component
$queryInterface = new MediaWikiQueryInterface(
$dbConnectionProvider,
new ExtendedMySQLAbstraction( $dbConnectionProvider )
@@ -158,7 +160,7 @@
$matchingEntityIds = $matchFinder->getMatchingEntities(
$description, $queryOptions );
$this->assertInternalType( 'array', $matchingEntityIds );
- $this->assertContainsOnly( 'int', $matchingEntityIds );
+ $this->assertContainsOnlyInstancesOf( 'Wikibase\EntityId',
$matchingEntityIds );
$this->assertEquals( $expectedIds, $matchingEntityIds );
}
@@ -171,7 +173,7 @@
new EntityId( 'property', 42 ),
new ValueDescription( new NumberValue( 1337 ) )
),
- array( 11120, 11150 )
+ array( new EntityId( 'item', 1112 ), new EntityId(
'item', 1115 ) )
);
$argLists[] = array(
@@ -187,7 +189,7 @@
new EntityId( 'property', 43 ),
new ValueDescription( new NumberValue( 1337 ) )
),
- array( 11130 )
+ array( new EntityId( 'item', 1113 ) )
);
$argLists[] = array(
@@ -195,7 +197,7 @@
new EntityId( 'property', 42 ),
new ValueDescription( new NumberValue( 72010 ) )
),
- array( 11140 )
+ array( new EntityId( 'item', 1114 ) )
);
return $argLists;
diff --git a/tests/integration/SQLStore/WritingIntegrationTest.php
b/tests/integration/SQLStore/WritingIntegrationTest.php
index 203340e..808b3cd 100644
--- a/tests/integration/SQLStore/WritingIntegrationTest.php
+++ b/tests/integration/SQLStore/WritingIntegrationTest.php
@@ -13,6 +13,7 @@
use Wikibase\Database\MediaWikiQueryInterface;
use Wikibase\Database\MessageReporter;
use Wikibase\Database\MWDB\ExtendedMySQLAbstraction;
+use Wikibase\Database\MWDB\ExtendedSQLiteAbstraction;
use Wikibase\Database\TableDefinition;
use Wikibase\EntityId;
use Wikibase\Item;
@@ -67,6 +68,7 @@
protected function newStore() {
$dbConnectionProvider = new LazyDBConnectionProvider( DB_MASTER
);
+ // TODO: use factory in DB component
$queryInterface = new MediaWikiQueryInterface(
$dbConnectionProvider,
new ExtendedMySQLAbstraction( $dbConnectionProvider )
@@ -117,7 +119,7 @@
);
$this->assertEquals(
- array( 88880 ),
+ array( new EntityId( 'item', 8888 ) ),
$this->findMatchingEntities( $propertyDescription )
);
@@ -169,7 +171,7 @@
);
$this->assertEquals(
- array( 44440 ),
+ array( new EntityId( 'item', 4444 ) ),
$this->findMatchingEntities( $propertyDescription )
);
diff --git a/tests/phpunit/SQLStore/Engine/DescriptionMatchFinderTest.php
b/tests/phpunit/SQLStore/Engine/DescriptionMatchFinderTest.php
index 311c2a7..cd46fe1 100644
--- a/tests/phpunit/SQLStore/Engine/DescriptionMatchFinderTest.php
+++ b/tests/phpunit/SQLStore/Engine/DescriptionMatchFinderTest.php
@@ -41,7 +41,8 @@
$this->getMockBuilder(
'Wikibase\QueryEngine\SQLStore\Schema' )
->disableOriginalConstructor()->getMock(),
$this->getMock(
'Wikibase\QueryEngine\PropertyDataValueTypeLookup' ),
- $this->getMock(
'Wikibase\QueryEngine\SQLStore\InternalEntityIdFinder' )
+ $this->getMock(
'Wikibase\QueryEngine\SQLStore\InternalEntityIdFinder' ),
+ $this->getMock(
'Wikibase\QueryEngine\SQLStore\InternalEntityIdInterpreter' )
);
}
@@ -89,18 +90,26 @@
$idTransformer = $this->getMock(
'Wikibase\QueryEngine\SQLStore\InternalEntityIdFinder' );
+ $idInterpreter = $this->getMock(
'Wikibase\QueryEngine\SQLStore\InternalEntityIdInterpreter' );
+
+ $idInterpreter->expects( $this->atLeastOnce() )
+ ->method( 'getExternalIdForEntity' )
+ ->with( $this->equalTo( 10 ) )
+ ->will( $this->returnValue( new EntityId( 'item', 1 ) )
);
+
$matchFinder = new DescriptionMatchFinder(
$queryEngine,
$schema,
$dvTypeLookup,
- $idTransformer
+ $idTransformer,
+ $idInterpreter
);
- $matchingInternalIds = $matchFinder->findMatchingEntities(
$description, $queryOptions );
+ $matchingIds = $matchFinder->findMatchingEntities(
$description, $queryOptions );
- $this->assertInternalType( 'array', $matchingInternalIds );
- $this->assertContainsOnly( 'int', $matchingInternalIds );
- $this->assertEquals( array( 10 ), $matchingInternalIds );
+ $this->assertInternalType( 'array', $matchingIds );
+ $this->assertContainsOnlyInstancesOf( 'Wikibase\EntityId',
$matchingIds );
+ $this->assertEquals( array( new EntityId( 'item', 1 ) ),
$matchingIds );
}
public function testFindMatchingEntitiesWithInvalidPropertyId() {
--
To view, visit https://gerrit.wikimedia.org/r/74645
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ibc104d0545e12ac5f6dfe31014056087db278e44
Gerrit-PatchSet: 19
Gerrit-Project: mediawiki/extensions/WikibaseQueryEngine
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: Denny Vrandecic <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits