r35975 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r35974‎ | r35975 | r35976 >
Date:17:35, 6 June 2008
Author:mkroetzsch
Status:old
Tags:
Comment:
Support for querying naries in new storage implementation
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2_Queries.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2_Queries.php
@@ -259,44 +259,14 @@
260260 $qid = SMWSQLStore2Query::$qnum;
261261 $query = new SMWSQLStore2Query();
262262 if ($description instanceof SMWSomeProperty) {
263 - $typeid = SMWDataValueFactory::getPropertyObjectTypeID($description->getProperty());
264 - $query->joinfield = "$query->alias.s_id";
265 - $pid = $this->m_store->getSMWPageID($description->getProperty()->getDBkey(), $description->getProperty()->getNamespace(),'');
266 - $pqid = SMWSQLStore2Query::$qnum;
267 - $pquery = new SMWSQLStore2Query();
268 - $pquery->type = SMW_SQL2_PROP_HIERARCHY;
269 - $pquery->joinfield = array($pid);
270 - $query->components[$pqid] = "$query->alias.p_id";
271 - $this->m_queries[$pqid] = $pquery;
272 - $sortfield = ''; // used if we should sort by this property
273 - switch ($typeid) {
274 - case '_wpg': case '__nry': // subconditions as subqueries (compiled)
275 - $query->jointable = 'smw_rels2';
276 - $sub = $this->compileQueries($description->getDescription());
277 - if ($sub >= 0) {
278 - $query->components[$sub] = "$query->alias.o_id";
279 - }
280 - if ( array_key_exists($description->getProperty()->getDBkey(), $this->m_sortkeys) ) {
281 - $query->from = ' INNER JOIN ' . $this->m_dbs->tableName('smw_ids') . " AS ids$query->alias ON ids$query->alias.smw_id=$query->alias.o_id";
282 - $sortfield = "ids$query->alias.smw_title"; /// TODO: as below, smw_ids here is possibly duplicated! Can we prevent that? (PERFORMANCE)
283 - }
284 - break;
285 - case '_txt': // no subconditions
286 - $query->jointable = 'smw_text2';
287 - break;
288 - default: // subquery only conj/disj of values, compile to single "where"
289 - $query->jointable = 'smw_atts2';
290 - $aw = $this->compileAttributeWhere($description->getDescription(),"$query->alias");
291 - if ($aw != '') {
292 - $query->where .= ($query->where?' AND ':'') . $aw;
293 - }
294 - if ( array_key_exists($description->getProperty()->getDBkey(), $this->m_sortkeys) ) {
295 - $sortfield = "$query->alias." . (SMWDataValueFactory::newTypeIDValue($typeid)->isNumeric()?'value_num':'value_xsd');
296 - }
297 - }
298 - if ($sortfield) {
299 - $query->sortfields[$description->getProperty()->getDBkey()] = $sortfield;
300 - }
 263+// $typeid = SMWDataValueFactory::getPropertyObjectTypeID($description->getProperty());
 264+// $typevalue = NULL;
 265+// if ($typeid == '__nry') {
 266+// $typevalue = SMWDataValueFactory::getPropertyObjectTypeValue($description->getProperty());
 267+// }
 268+// $pid = $this->m_store->getSMWPageID($description->getProperty()->getDBkey(), $description->getProperty()->getNamespace(),'');
 269+// $this->compilePropertyCondition($query, $pid, $typeid, $typevalue, $description->getProperty()->getDBkey(), $description->getDescription());
 270+ $this->compilePropertyCondition($query, $description->getProperty(), $description->getDescription());
301271 } elseif ($description instanceof SMWNamespaceDescription) { /// TODO: One instance of smw_ids on s_id always suffices (swm_id is KEY)! Doable in execution ... (PERFORMANCE)
302272 $query->jointable = 'smw_ids';
303273 $query->joinfield = "$query->alias.smw_id";
@@ -330,8 +300,6 @@
331301 $query->components[$cqid] = "$query->alias.o_id";
332302 $this->m_queries[$cqid] = $cquery;
333303 }
334 - } elseif ($description instanceof SMWValueList) {
335 - $qid = -1; /// TODO
336304 } elseif ($description instanceof SMWValueDescription) { // only processsed here for '_wpg'
337305 if ($description->getDatavalue()->getTypeID() == '_wpg') {
338306 if ($description->getComparator() == SMW_CMP_EQ) {
@@ -354,7 +322,7 @@
355323 $query->where = "$query->alias.smw_title$comp" . $this->m_dbs->addQuotes($value);
356324 }
357325 }
358 - } else { // (e.g. SMWThingDescription)
 326+ } else { // (e.g. SMWThingDescription, SMWValueList is also treated elswhere)
359327 $qid = -1; // no condition
360328 }
361329 if ($qid >= 0) {
@@ -369,6 +337,88 @@
370338 }
371339
372340 /**
 341+ * Modify the given query object to account for some property condition for the given property.
 342+ * The parameter $property may be a Title object or an internal storage id. This is what makes
 343+ * this method useful: it can be used even with internal properties that have no MediaWiki Title.
 344+ * $typeid is set if property ids are used, since internal properties may not have a defined type.
 345+ */
 346+ protected function compilePropertyCondition(&$query, $property, SMWDescription $valuedesc, $typeid=false) {
 347+ $query->joinfield = "$query->alias.s_id";
 348+ if ($property instanceof Title) {
 349+ $typeid = SMWDataValueFactory::getPropertyObjectTypeID($property);
 350+ $pid = $this->m_store->getSMWPageID($property->getDBkey(), $property->getNamespace(),'');
 351+ $sortkey = $property->getDBkey();
 352+ // also make property hierarchy
 353+ $pqid = SMWSQLStore2Query::$qnum;
 354+ $pquery = new SMWSQLStore2Query();
 355+ $pquery->type = SMW_SQL2_PROP_HIERARCHY;
 356+ $pquery->joinfield = array($pid);
 357+ $query->components[$pqid] = "$query->alias.p_id";
 358+ $this->m_queries[$pqid] = $pquery;
 359+ } else {
 360+ $pid = $property;
 361+ $sortkey = false;
 362+ // no property hierarchy
 363+ $query->where = "$query->alias.p_id=" . $this->m_dbs->addQuotes($pid);
 364+ }
 365+ $sortfield = ''; // used if we should sort by this property
 366+ switch ($typeid) {
 367+ case '_wpg': // subconditions as subqueries (compiled)
 368+ $query->jointable = 'smw_rels2';
 369+ $sub = $this->compileQueries($valuedesc);
 370+ if ($sub >= 0) {
 371+ $query->components[$sub] = "$query->alias.o_id";
 372+ }
 373+ if ( $sortkey && array_key_exists($sortkey, $this->m_sortkeys) ) {
 374+ $query->from = ' INNER JOIN ' . $this->m_dbs->tableName('smw_ids') . " AS ids$query->alias ON ids$query->alias.smw_id=$query->alias.o_id";
 375+ $sortfield = "ids$query->alias.smw_title"; /// TODO: as below, smw_ids here is possibly duplicated! Can we prevent that? (PERFORMANCE)
 376+ }
 377+ break;
 378+ case '__nry':
 379+ $query->jointable = 'smw_rels2';
 380+ if ($valuedesc instanceof SMWValueList) { // anything else is ignored!
 381+ $typevalue = SMWDataValueFactory::getPropertyObjectTypeValue($property);
 382+ $typelabels = $typevalue->getTypeLabels();
 383+ reset($typelabels);
 384+ $subqid = SMWSQLStore2Query::$qnum;
 385+ $subquery = new SMWSQLStore2Query();
 386+ $subquery->type = SMW_SQL2_CONJUNCTION;
 387+ $query->components[$subqid] = "$query->alias.o_id";
 388+ $this->m_queries[$subqid] = $subquery;
 389+ for ($i=0; $i<$valuedesc->getCount(); $i++) {
 390+ $desc = $valuedesc->getDescription($i);
 391+ if ($desc !== NULL) {
 392+ $stypeid = SMWDataValueFactory::findTypeID(current($typelabels));
 393+ $valpid = $this->m_store->getSMWPageID(strval($i),SMW_NS_PROPERTY,SMW_SQL2_SMWIW);
 394+ $valqid = SMWSQLStore2Query::$qnum;
 395+ $valquery = new SMWSQLStore2Query();
 396+ $this->compilePropertyCondition($valquery, $valpid, $desc, $stypeid);
 397+ $subquery->components[$valqid] = true;
 398+ $this->m_queries[$valqid] = $valquery;
 399+ }
 400+ next($typelabels);
 401+ }
 402+ }
 403+ break;
 404+ case '_txt': // no subconditions
 405+ $query->jointable = 'smw_text2';
 406+ break;
 407+ default: // subquery only conj/disj of values, compile to single "where"
 408+ $query->jointable = 'smw_atts2';
 409+ $aw = $this->compileAttributeWhere($valuedesc,"$query->alias");
 410+ if ($aw != '') {
 411+ $query->where .= ($query->where?' AND ':'') . $aw;
 412+ }
 413+ if ( $sortkey && array_key_exists($sortkey, $this->m_sortkeys) ) {
 414+ $sortfield = "$query->alias." . (SMWDataValueFactory::newTypeIDValue($typeid)->isNumeric()?'value_num':'value_xsd');
 415+ }
 416+ }
 417+ if ($sortfield) {
 418+ $query->sortfields[$sortkey] = $sortfield;
 419+ }
 420+ }
 421+
 422+ /**
373423 * Given an SMWDescription that is just a conjunction or disjunction of
374424 * SMWValueDescription objects, create a plain WHERE condition string for it.
375425 */

Status & tagging log