Comments (5)
Thanks for filing the issue @ikarennina.
The SPARQL standard has a provision to specify OPTIONAL clauses. Given your description, it is safe to assume constraints are not a concern, but multiple optional clauses are.
Adding only the OPTIONAL
part only may require changes to the whole stack (lexer, parser, planner, and executor) but does not require changes to the driver interface; the resolution and orchestration is all done by the planner and executor in memory. Constraints, however, would likely require changes on the driver interface, hence I am going to say it is safe to leave them out of scope for now.
The proposed change would allow to mark clauses with the OPTIONAL
. The example adapted the syntax from the SPARQL documentation to BQL. It also shows the benefits on a reified query
SELECT ?user, ?label, ?score
FROM ?social_graph
WHERE {
?bn "_subject"@[] /user<Joe> .
?bn "_predicate"@[] "follows"@[] .
?bn "_predicate"@[] ?user .
?bn "tag"@[] ?label .
?bn "score"@[] ?score
};
The above example would only return row where all three binding (?user
, ?label
, ?score
) can be resolved. If for some reason the "tag@[]
or score@[]
predicates are not present, you would not get results back for those users. The use of OPTIONAL
on those last two clauses would return all the folks that /user<Joe>
, regardless if those clauses could be binded ore not. The new query would look like as:
SELECT ?user, ?label, ?score
FROM ?social_graph
WHERE {
?bn "_subject"@[] /user<Joe> .
?bn "_predicate"@[] "follows"@[] .
?bn "_predicate"@[] ?user .
OPTIONAL { ?bn "tag"@[] ?label } .
OPTIONAL { ?bn "score"@[] ?score}
};
@ikarennina would this extension help you address your use case?
from badwolf.
Yes, that's exactly what I need. I suppose that in the absence of label and score they would contain some kind of null value?
from badwolf.
Correct. The results table right now allows to return a *Cell where no values are set. That is you would get on the case that the binding on an optional clause. A *Cell without any pointer set is what you would get for OPTIONAL
that did not bind.
from badwolf.
Current changes are done all the way to the execution of the plan. At this point I need to revisit the execution itself and how the data gets merge on the presence of optional clauses. @ikarennina this may take me a few weeks given the shoestring bandwidth right now 🙃 .
from badwolf.
Changes have been working as described originally in this issue. Closing it for now.
from badwolf.
Related Issues (20)
- BQL: trailing dot for sequential statements HOT 1
- Two ways of doing reification with CONSTRUCT are not yielding equivalent and correct results
- Reification inside CONSTRUCT is not accepting breakline before partial statements
- HAVING clause should not require parentheses when involving AND or OR
- Program freezes when querying time anchor on datasets with mixed mutable/immutable triples HOT 1
- Users should be able to specify if they want to include or not immutable triples on results from queries involving AFTER, BEFORE and BETWEEN
- Create documentation about OPTIONAL keyword HOT 1
- Allow more elaborate patterns (like specifying suffix/prefix) for bindings inside HAVING clauses HOT 1
- Expand support of TYPE extraction for literals and predicates too, in addition to nodes HOT 2
- FILTER keyword HOT 1
- TestPlannerQuery in planner_test.go should test deeper
- "BETWEEN start_date, end_date" should return an error if "start_date > end_date"
- Refactor tests in BadWolf to use t.Run()
- Make LIMIT be processed in the driver level
- Table results seems to contains a value with a empty binding
- Still active? HOT 9
- TestPartialUUID fails on Windows HOT 3
- BQL: Time anchor placeholders HOT 1
- Allow specifying only last temporal triple on queries HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from badwolf.