On May 18, 7:55 pm, "John L. Clark" <
john.l.cl...@gmail.com> wrote:
John,
> You're using RDFLib from Subversion trunk? Also, what version of
> PostgreSQL are you using?
I'm using Python2.6, RDFLib from trunk - now tip :-) and PostgreSQL
version is 8.2.5
> Can you post a bit more about the setup code you're using that's
> emitting the 'STRAIGHT_JOIN'? The PostgreSQL subclass should override
> that in all the important places.
I did look through the code and I tried explicitly setting the
instantiated store's select_modifier attrib to the empty string, to no
avail.
This is what I get:
bash-3.2$ python2.6
Python 2.6 (r26:66714, Dec 4 2008, 16:17:57)
[GCC 4.0.1 (Apple Inc. build 5484)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import rdflib
>>> from rdflib.graph import ConjunctiveGraph as Graph
>>> from rdflib import plugin
>>> from rdflib.store import Store, NO_STORE, VALID_STORE
>>> from rdflib.namespace import Namespace
>>> from rdflib.term import Literal, URIRef
>>> default_graph_uri = "
http://rdflib.net/rdfstore"
>>> configString = "host=localhost,user=foo,password=baz,db=rdflib"
>>> store = plugin.get('PostgreSQL', Store)('rdfstore')
rdflib/store/AbstractSQLStore.py:5: DeprecationWarning: the sha module
is deprecated; use the hashlib module instead
import sha,sys, weakref
>>> rt = store.open(configString,create=False)
table kb_7b066eca61_relations Doesn't exist
table kb_7b066eca61_relations Doesn't exist
>>> if rt == NO_STORE:
... store.open(configString,create=True)
... else:
... assert rt == VALID_STORE,"There underlying store is corrupted"
...
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
AssertionError: There underlying store is corrupted
>>> store.open(configString,create=True)
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index
"kb_7b066eca61_namespace_binds_pkey" for table
"kb_7b066eca61_namespace_binds"
NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index
"kb_7b066eca61_identifiers_pkey" for table "kb_7b066eca61_identifiers"
NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index
"kb_7b066eca61_literals_pkey" for table "kb_7b066eca61_literals"
1
>>> graph = Graph(store, identifier = URIRef(default_graph_uri))
>>> print "Triples in graph before add: ", len(graph)
Triples in graph before add: 0
>>> rdflib = Namespace('
http://rdflib.net/test/')
>>> graph.add((rdflib['pic:1'], rdflib['name'], Literal('Jane & Bob')))
>>> graph.add((rdflib['pic:2'], rdflib['name'], Literal('Squirrel in Tree')))
>>> graph.commit()
WARNING: there is no transaction in progress
>>> print "Triples in graph after add: ", len(graph)
Triples in graph after add: 2
>>> print graph.serialize()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "rdflib/graph.py", line 685, in serialize
serializer.serialize(stream, base=base, encoding=encoding, **args)
File "rdflib/syntax/serializers/XMLSerializer.py", line 50, in
serialize
bindings = list(self.__bindings())
File "rdflib/syntax/serializers/XMLSerializer.py", line 25, in
__bindings
for predicate in uniq(store.predicates()):
File "rdflib/util.py", line 27, in uniq
map(set.__setitem__, sequence, [])
File "rdflib/graph.py", line 463, in predicates
for s, p, o in self.triples((subject, None, object)):
File "rdflib/graph.py", line 905, in triples
for (s, p, o), cg in self.store.triples((s, p, o),
context=context):
File "rdflib/store/MySQL.py", line 1250, in triples
rt=PatternResolution
((subject,predicate,obj,context),c,self.partitions,fetchall=False)
File "rdflib/store/FOPLRelationalModel/BinaryRelationPartition.py",
line 873, in PatternResolution
cursor.execute(query,tuple(unionQueriesParams))
File "build/bdist.macosx-10.5-i386/egg/pgdb.py", line 168, in
execute
self.executemany(operation, (params,))
File "build/bdist.macosx-10.5-i386/egg/pgdb.py", line 189, in
executemany
raise DatabaseError, "error '%s' in '%s'" % ( msg, sql )
pg.DatabaseError: error 'ERROR: syntax error at or near "rt_subject"
LINE 1: (SELECT STRAIGHT_JOIN rt_subject.lexical as
subject,rt_subje...
^
' in '(SELECT STRAIGHT_JOIN rt_subject.lexical as
subject,rt_subject.term_type as subjectTermType,rt_predicate.lexical
as predicate,rt_predicate.term_type as
predicateTermType,rt_object.lexical as object,'L' as
objectTermType,rt_context.lexical as context,rt_context.term_type as
contextTermType,rt_data_type.lexical as
dataType,kb_7b066eca61_literalProperties.language as language FROM
kb_7b066eca61_literalProperties LEFT JOIN kb_7b066eca61_identifiers
rt_data_type ON (kb_7b066eca61_literalProperties.data_type =
rt_data_type.id) INNER JOIN kb_7b066eca61_identifiers rt_predicate ON
(kb_7b066eca61_literalProperties.predicate =
rt_predicate.id AND
kb_7b066eca61_literalProperties.predicate_term =
rt_predicate.term_type) INNER JOIN kb_7b066eca61_identifiers
rt_context ON (kb_7b066eca61_literalProperties.context =
rt_context.id
AND kb_7b066eca61_literalProperties.context_term =
rt_context.term_type) INNER JOIN kb_7b066eca61_literals rt_object ON
(kb_7b066eca61_literalProperties.object =
rt_object.id) INNER JOIN
kb_7b066eca61_identifiers rt_subject ON
(kb_7b066eca61_literalProperties.subject =
rt_subject.id AND
kb_7b066eca61_literalProperties.subject_term = rt_subject.term_type)
WHERE kb_7b066eca61_literalProperties.context_term != 'F') union all
(SELECT STRAIGHT_JOIN
rt_subject.lexical,rt_subject.term_type,rt_predicate.lexical,rt_predicate.term_type,rt_object.lexical,rt_object.term_type,rt_context.lexical,rt_context.term_type,NULL,NULL
FROM kb_7b066eca61_relations INNER JOIN kb_7b066eca61_identifiers
rt_predicate ON (kb_7b066eca61_relations.predicate =
rt_predicate.id
AND kb_7b066eca61_relations.predicate_term = rt_predicate.term_type)
INNER JOIN kb_7b066eca61_identifiers rt_context ON
(kb_7b066eca61_relations.context =
rt_context.id AND
kb_7b066eca61_relations.context_term = rt_context.term_type) INNER
JOIN kb_7b066eca61_identifiers rt_object ON
(kb_7b066eca61_relations.object =
rt_object.id AND
kb_7b066eca61_relations.object_term = rt_object.term_type) INNER JOIN
kb_7b066eca61_identifiers rt_subject ON
(kb_7b066eca61_relations.subject =
rt_subject.id AND
kb_7b066eca61_relations.subject_term = rt_subject.term_type) WHERE
kb_7b066eca61_relations.context_term != 'F') union all (SELECT
STRAIGHT_JOIN rt_subject.lexical,rt_subject.term_type,'http://
www.w3.org/1999/02/22-rdf-syntax-ns#type','U',rt_object.lexical,rt_object.term_type,rt_context.lexical,rt_context.term_type,NULL,NULL
FROM kb_7b066eca61_associativeBox INNER JOIN kb_7b066eca61_identifiers
rt_object ON (kb_7b066eca61_associativeBox.class =
rt_object.id AND
kb_7b066eca61_associativeBox.class_term = rt_object.term_type) INNER
JOIN kb_7b066eca61_identifiers rt_context ON
(kb_7b066eca61_associativeBox.context =
rt_context.id AND
kb_7b066eca61_associativeBox.context_term = rt_context.term_type)
INNER JOIN kb_7b066eca61_identifiers rt_subject ON
(kb_7b066eca61_associativeBox.member =
rt_subject.id AND
kb_7b066eca61_associativeBox.member_term = rt_subject.term_type) WHERE
kb_7b066eca61_associativeBox.context_term != 'F') ORDER BY
subject,predicate,object'
Switching API to psycopg2 gives a smoother drive but the STRAIGHT_JOIN
is still there.
bash-3.2$ python2.6
Python 2.6 (r26:66714, Dec 4 2008, 16:17:57)
[GCC 4.0.1 (Apple Inc. build 5484)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import rdflib
>>> from rdflib.graph import ConjunctiveGraph as Graph
>>> from rdflib import plugin
>>> from rdflib.store import Store, NO_STORE, VALID_STORE
>>> from rdflib.namespace import Namespace
>>> from rdflib.term import Literal, URIRef
>>> default_graph_uri = "
http://rdflib.net/rdfstore"
>>> configString = "host=localhost,user=httpd,password=,db=rdflib"
>>> store = plugin.get('PostgreSQL', Store)('rdfstore')
rdflib/store/AbstractSQLStore.py:5: DeprecationWarning: the sha module
is deprecated; use the hashlib module instead
import sha,sys, weakref
>>> rt = store.open(configString,create=False)
>>> if rt == NO_STORE:
... store.open(configString,create=True)
... else:
... assert rt == VALID_STORE,"There underlying store is corrupted"
...
>>> graph = Graph(store, identifier = URIRef(default_graph_uri))
>>> print "Triples in graph before add: ", len(graph)
Triples in graph before add: 2
>>> rdflib = Namespace('
http://rdflib.net/test/')
>>> graph.add((rdflib['pic:1'], rdflib['name'], Literal('Jane & Bob')))
>>> graph.add((rdflib['pic:2'], rdflib['name'], Literal('Squirrel in Tree')))
>>> graph.commit()
>>> print "Triples in graph after add: ", len(graph)
Triples in graph after add: 4
>>> print graph.serialize()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "rdflib/graph.py", line 685, in serialize
serializer.serialize(stream, base=base, encoding=encoding, **args)
File "rdflib/syntax/serializers/XMLSerializer.py", line 50, in
serialize
bindings = list(self.__bindings())
File "rdflib/syntax/serializers/XMLSerializer.py", line 25, in
__bindings
for predicate in uniq(store.predicates()):
File "rdflib/util.py", line 27, in uniq
map(set.__setitem__, sequence, [])
File "rdflib/graph.py", line 463, in predicates
for s, p, o in self.triples((subject, None, object)):
File "rdflib/graph.py", line 905, in triples
for (s, p, o), cg in self.store.triples((s, p, o),
context=context):
File "rdflib/store/MySQL.py", line 1250, in triples
rt=PatternResolution
((subject,predicate,obj,context),c,self.partitions,fetchall=False)
File "rdflib/store/FOPLRelationalModel/BinaryRelationPartition.py",
line 873, in PatternResolution
cursor.execute(query,tuple(unionQueriesParams))
psycopg2.ProgrammingError: syntax error at or near "rt_subject"
LINE 1: (SELECT STRAIGHT_JOIN rt_subject.lexical as
subject,rt_subje...
^
It's a crude workaround but like as not it won't be needed for long
and the PostgreSQL back-end isn't official yet.
If there's a proper fix tho', that'd be useful.
Cheers,
Graham Higgins