Use separate insert/delete statements to work around Blazegraph bug
authorStanislav Malyshev <smalyshev@gmail.com>
Mon, 6 Aug 2018 23:40:29 +0000 (16:40 -0700)
committerSmalyshev <smalyshev@wikimedia.org>
Mon, 13 Aug 2018 23:24:52 +0000 (23:24 +0000)
Bug https://github.com/blazegraph/database/issues/100 happens on DELETE/INSERT
but not on separate delete and insert, try to work around it

Change-Id: Iba6a98dde6f4bea9051cd6dee91fb19db5eca10e
Bug: T201217

maintenance/categoryChangesAsRdf.php
tests/phpunit/data/categoriesrdf/change.sparql
tests/phpunit/data/categoriesrdf/delete.sparql
tests/phpunit/data/categoriesrdf/move.sparql

index bf7a22d..d613352 100644 (file)
@@ -39,6 +39,20 @@ INSERT DATA {
 
 SPARQL;
 
+       /**
+        * Delete query
+        */
+       const SPARQL_DELETE = <<<SPARQLD
+DELETE {
+?category ?x ?y
+} WHERE {
+   VALUES ?category {
+     %s
+   }
+};
+
+SPARQLD;
+
        /**
         * Delete/Insert query
         */
@@ -102,8 +116,8 @@ SPARQLDI;
                global $wgRCMaxAge;
 
                $this->initialize();
-
                $startTS = new MWTimestamp( $this->getOption( "start" ) );
+
                $endTS = new MWTimestamp( $this->getOption( "end" ) );
                $now = new MWTimestamp();
 
@@ -150,6 +164,18 @@ SPARQLDI;
                fwrite( $output, $this->updateTS( $this->endTS ) );
        }
 
+       /**
+        * Get the text of SPARQL INSERT DATA clause
+        * @return string
+        */
+       private function getInsertRdf() {
+               $rdfText = $this->getRdf();
+               if ( !$rdfText ) {
+                       return "";
+               }
+               return sprintf( self::SPARQL_INSERT, $rdfText );
+       }
+
        /**
         * Get SPARQL for updating set of categories
         * @param IDatabase $dbr
@@ -167,9 +193,8 @@ SPARQLDI;
                        $this->writeParentCategories( $dbr, $pages );
                }
 
-               return "# $mark\n" . sprintf( self::SPARQL_DELETE_INSERT,
-                               $this->getRdf(),
-                               implode( ' ', $deleteUrls ) );
+               return "# $mark\n" . sprintf( self::SPARQL_DELETE, implode( ' ', $deleteUrls ) ) .
+                       $this->getInsertRdf();
        }
 
        /**
@@ -483,7 +508,7 @@ SPARQL;
 
                        $this->writeParentCategories( $dbr, $pages );
 
-                       fwrite( $output, sprintf( self::SPARQL_INSERT, $this->getRdf() ) );
+                       fwrite( $output, $this->getInsertRdf() );
                }
        }
 
@@ -510,7 +535,7 @@ SPARQL;
                        }
 
                        $this->writeParentCategories( $dbr, $pages );
-                       fwrite( $output, sprintf( self::SPARQL_INSERT, $this->getRdf() ) );
+                       fwrite( $output, $this->getInsertRdf() );
                }
        }
 
index d7ec83a..d1a6a62 100644 (file)
@@ -1,7 +1,12 @@
 # Changes
 DELETE {
 ?category ?x ?y
-} INSERT {
+} WHERE {
+   VALUES ?category {
+     <http://acme.test/wiki/Category:Changed_category>
+   }
+};
+INSERT DATA {
 
 <http://acme.test/wiki/Category:Changed_category> a mediawiki:Category ;
        rdfs:label "Changed category" ;
@@ -9,8 +14,4 @@ DELETE {
        mediawiki:subcategories "2"^^xsd:integer ;
        mediawiki:isInCategory <http://acme.test/wiki/Category:Parent_of_30> .
 
-} WHERE {
-   VALUES ?category {
-     <http://acme.test/wiki/Category:Changed_category>
-   }
 };
index 7fb642d..043d9c3 100644 (file)
@@ -1,8 +1,6 @@
 # Deletes
 DELETE {
 ?category ?x ?y
-} INSERT {
-
 } WHERE {
    VALUES ?category {
      <http://acme.test/wiki/Category:Test> <http://acme.test/wiki/Category:Test_2>
index c9f284e..d22bc47 100644 (file)
@@ -1,7 +1,12 @@
 # Moves
 DELETE {
 ?category ?x ?y
-} INSERT {
+} WHERE {
+   VALUES ?category {
+     <http://acme.test/wiki/Category:Test> <http://acme.test/wiki/Category:MovedTo> <http://acme.test/wiki/Category:Test_2> <http://acme.test/wiki/Category:Test_3> <http://acme.test/wiki/Category:Test_4>
+   }
+};
+INSERT DATA {
 
 <http://acme.test/wiki/Category:MovedTo> a mediawiki:Category ;
        rdfs:label "MovedTo" ;
@@ -17,8 +22,4 @@ DELETE {
 
 <http://acme.test/wiki/Category:AlsoMoved> mediawiki:isInCategory <http://acme.test/wiki/Category:Parent_of_5> .
 
-} WHERE {
-   VALUES ?category {
-     <http://acme.test/wiki/Category:Test> <http://acme.test/wiki/Category:MovedTo> <http://acme.test/wiki/Category:Test_2> <http://acme.test/wiki/Category:Test_3> <http://acme.test/wiki/Category:Test_4>
-   }
 };