Skip to content

Commit

Permalink
Revert "SPARQL VALUES patterns"
Browse files Browse the repository at this point in the history
  • Loading branch information
dpetran committed Jun 17, 2024
1 parent a74defb commit 16a7cc2
Show file tree
Hide file tree
Showing 14 changed files with 106 additions and 788 deletions.
42 changes: 19 additions & 23 deletions resources/sparql.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ UpdateUnit ::= Update
Prologue ::= ( BaseDecl | PrefixDecl )*
BaseDecl ::= <'BASE'> WS IRIREF
PrefixDecl ::= <'PREFIX'> WS PNAME_NS WS IRIREF
SelectQuery ::= WS SelectClause WS DatasetClause WS WhereClause WS SolutionModifier WS
SelectQuery ::= WS SelectClause WS DatasetClause* WS WhereClause WS SolutionModifier WS
SubSelect ::= SelectClause WhereClause SolutionModifier ValuesClause
SelectClause ::= WS <'SELECT'> WS ( 'DISTINCT' | 'REDUCED')? ( ( WS ( Var | ( <'('> Expression WS 'AS' WS Var <')'> ) ) )+ | ( WS '*' ) )
ConstructQuery ::= 'CONSTRUCT' ( ConstructTemplate DatasetClause WhereClause SolutionModifier | DatasetClause 'WHERE' '{' TriplesTemplate? '}' SolutionModifier )
DescribeQuery ::= 'DESCRIBE' ( VarOrIri+ | '*' ) DatasetClause WhereClause? SolutionModifier
AskQuery ::= 'ASK' DatasetClause WhereClause SolutionModifier
Modifiers ::= (ValuesClause? | PrettyPrint? ) (PrettyPrint? | ValuesClause? )
DatasetClause ::= FromClause*
<FromClause> ::= <'FROM'> WS ( DefaultGraphClause | NamedGraphClause )
ConstructQuery ::= 'CONSTRUCT' ( ConstructTemplate DatasetClause* WhereClause SolutionModifier | DatasetClause* 'WHERE' '{' TriplesTemplate? '}' SolutionModifier )
DescribeQuery ::= 'DESCRIBE' ( VarOrIri+ | '*' ) DatasetClause* WhereClause? SolutionModifier
AskQuery ::= 'ASK' DatasetClause* WhereClause SolutionModifier
Modifiers ::= (ValuesClause? | PrettyPrint? ) (PrettyPrint? | ValuesClause? )
DatasetClause ::= <'FROM'> WS ( DefaultGraphClause | NamedGraphClause )
DefaultGraphClause ::= SourceSelector
NamedGraphClause ::= <'NAMED'> WS SourceSelector
NamedGraphClause ::= <'NAMED'> SourceSelector
<SourceSelector> ::= iri
WhereClause ::= <'WHERE'?> WS GroupGraphPattern WS
SolutionModifier ::= GroupClause? HavingClause? OrderClause? LimitOffsetClauses?
Expand Down Expand Up @@ -57,15 +56,13 @@ GroupGraphPatternSub ::= WS TriplesBlock? ( GraphPatternNotTriples WS <'.'?>
TriplesBlock ::= WS TriplesSameSubjectPath WS ( <'.'> TriplesBlock? WS )?
GraphPatternNotTriples ::= GroupOrUnionGraphPattern | OptionalGraphPattern | MinusGraphPattern | GraphGraphPattern | ServiceGraphPattern | Filter | Bind | InlineData
OptionalGraphPattern ::= <'OPTIONAL'> GroupGraphPattern
GraphGraphPattern ::= <'GRAPH'> WS VarOrIri WS GroupGraphPattern
ServiceGraphPattern ::= <'SERVICE'> WS 'SILENT'? WS VarOrIri GroupGraphPattern
GraphGraphPattern ::= 'GRAPH' VarOrIri GroupGraphPattern
ServiceGraphPattern ::= 'SERVICE' 'SILENT'? VarOrIri GroupGraphPattern
Bind ::= <'BIND' WS '(' WS> Expression <WS 'AS' WS> Var <WS ')' WS>
InlineData ::= <'VALUES'> WS DataBlock
<DataBlock> ::= InlineDataOneVar | InlineDataFull
InlineDataOneVar ::= Var <'{'> WS DataBlockValue* <'}'>
InlineDataFull ::= ( NIL | VarList ) WS <'{'> WS ( ValueList WS | NIL )* <'}'>
VarList ::= ( <'('> Var* <')'> )
ValueList ::= ( <'('> WS DataBlockValue* <')'> )
InlineDataFull ::= ( NIL | '(' Var* ')' ) '{' ( '(' DataBlockValue* ')' | NIL )* '}'
DataBlockValue ::= iri | RDFLiteral | NumericLiteral | BooleanLiteral | 'UNDEF' WS
MinusGraphPattern ::= 'MINUS' GroupGraphPattern
GroupOrUnionGraphPattern ::= GroupGraphPattern ( <'UNION'> GroupGraphPattern )*
Expand All @@ -79,7 +76,7 @@ ConstructTriples ::= TriplesSameSubject ( '.' ConstructTriples? )?
TriplesSameSubject ::= VarOrTerm PropertyListNotEmpty | TriplesNode PropertyList
PropertyList ::= PropertyListNotEmpty?
PropertyListNotEmpty ::= Verb ObjectList ( <';'> WS ( Verb ObjectList )? )*
Verb ::= VarOrIri | Type
Verb ::= VarOrIri | 'a'
ObjectList ::= Object ( <','> WS Object )*
Object ::= GraphNode
TriplesSameSubjectPath ::= VarOrTerm PropertyListPathNotEmpty | TriplesNodePath PropertyListPath WS
Expand All @@ -95,9 +92,9 @@ PathSequence ::= PathEltOrInverse ( <'/'> PathEltOrInverse )*
<PathElt> ::= PathPrimary PathMod?
<PathEltOrInverse> ::= PathElt | <'^'> PathElt
PathMod ::= '?' | '*' | ('+' INTEGER?) WS
PathPrimary ::= iri | Type | '!' PathNegatedPropertySet | '(' Path ')'
PathPrimary ::= iri | 'a' | '!' PathNegatedPropertySet | '(' Path ')'
PathNegatedPropertySet ::= PathOneInPropertySet | '(' ( PathOneInPropertySet ( '|' PathOneInPropertySet )* )? ')'
PathOneInPropertySet ::= iri | Type | '^' ( iri | Type )
PathOneInPropertySet ::= iri | 'a' | '^' ( iri | 'a' )
Integer ::= INTEGER
TriplesNode ::= Collection | BlankNodePropertyList
BlankNodePropertyList ::= '[' PropertyListNotEmpty ']'
Expand All @@ -108,15 +105,14 @@ CollectionPath ::= '(' GraphNodePath+ ')'
<GraphNode> ::= VarOrTerm | TriplesNode
<GraphNodePath> ::= VarOrTerm | TriplesNodePath
<VarOrTerm> ::= Var | GraphTerm WS
<VarOrIri> ::= Var | iri WS
VarOrIri ::= Var | iri WS
Var ::= VAR1 WS | VAR2 WS
<Type> ::= (WS 'a' WS)
<GraphTerm> ::= iri | RDFLiteral | NumericLiteral | BooleanLiteral | BlankNode | NIL
Expression ::= WS ConditionalOrExpression WS
ConditionalOrExpression ::= ConditionalAndExpression ( <'||'> ConditionalAndExpression )*
ConditionalAndExpression ::= ValueLogical ( <'&&'> ValueLogical )*
<ConditionalOrExpression> ::= ConditionalAndExpression ( <'||'> ConditionalAndExpression )*
<ConditionalAndExpression> ::= ValueLogical ( <'&&'> ValueLogical )*
<ValueLogical> ::= RelationalExpression
RelationalExpression ::= NumericExpression WS ( '=' NumericExpression | '!=' NumericExpression | '<' NumericExpression | '>' NumericExpression | '<=' NumericExpression | '>=' NumericExpression | 'IN' WS ExpressionList | 'NOT' WS 'IN' WS ExpressionList )?
RelationalExpression ::= NumericExpression WS ( '=' NumericExpression | '!=' NumericExpression | '<' NumericExpression | '>' NumericExpression | '<=' NumericExpression | '>=' NumericExpression | 'IN' ExpressionList | 'NOT' 'IN' ExpressionList )?
NumericExpression ::= WS AdditiveExpression WS

<AdditiveExpression> ::= MultiplicativeExpression ( '+' MultiplicativeExpression | '-' MultiplicativeExpression | ( NumericLiteralPositive | NumericLiteralNegative ) ( ( '*' UnaryExpression ) | ( '/' UnaryExpression ) )* )*
Expand Down Expand Up @@ -192,7 +188,7 @@ RegexExpression ::= <'REGEX'> <'('> Expression <','> Expression ( <','> Expr
SubstringExpression ::= <'SUBSTR'> <'('> Expression <','> Expression ( <','> Expression )? <')'>
StrReplaceExpression ::= <'REPLACE'> <'('> Expression <','> Expression <','> Expression ( <','> Expression )? <')'>
ExistsFunc ::= <'EXISTS'> GroupGraphPattern
NotExistsFunc ::= <'NOT'> WS <'EXISTS'> GroupGraphPattern
NotExistsFunc ::= <'NOT'> <'EXISTS'> GroupGraphPattern
Aggregate ::= 'COUNT' WS <'('> WS 'DISTINCT'? WS ( '*' | Expression ) WS <')'> WS
| 'SUM' WS <'('> WS 'DISTINCT'? Expression <')'>
| 'MIN' <'('> WS 'DISTINCT'? Expression <')'>
Expand All @@ -218,7 +214,7 @@ IRIREF ::= #"<[^<>\"{}|^`\x00-\x20]*>" WS
BLANK_NODE_LABEL ::= '_:' ( PN_CHARS_U | #"[0-9]" ) ((PN_CHARS|'.')* PN_CHARS)?
<VAR1> ::= <'?'> VARNAME
<VAR2> ::= <'$'> VARNAME
LANGTAG ::= #"@[a-zA-Z]+(-[a-zA-Z0-9]+)*" WS
LANGTAG ::= #"@[a-zA-Z]+-[a-zA-Z0-9]*" WS
<INTEGER> ::= #"[0-9]+"
<DECIMAL> ::= #"[0-9]*\.[0-9]*"
<DOUBLE> ::= #"[0-9]+\.[0-9]*|(\.[0-9]+)|([0-9]+)" EXPONENT
Expand Down
1 change: 0 additions & 1 deletion src/clj/fluree/db/constants.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
(def ^:const iri-rdf-type "http://www.w3.org/1999/02/22-rdf-syntax-ns#type")
(def ^:const iri-class "http://www.w3.org/2000/01/rdf-schema#Class")
(def ^:const iri-lang-string "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString")
(def ^:const iri-string "http://www.w3.org/2001/XMLSchema#string")

;; rdfs
(def ^:const iri-rdfs:Class "http://www.w3.org/2000/01/rdf-schema#Class")
Expand Down
7 changes: 1 addition & 6 deletions src/clj/fluree/db/query/exec/eval.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,9 @@
[x]
(str x))

(defn in
[term expressions]
(contains? (set expressions) term))

(def allowed-scalar-fns
'#{&& || ! > < >= <= = + - * / quot and bound coalesce if lang nil? as
not not= or re-find re-pattern in
not not= or re-find re-pattern
;; string fns
strStarts strEnds subStr strLen ucase lcase contains strBefore strAfter concat regex replace
;; numeric fns
Expand Down Expand Up @@ -324,7 +320,6 @@
count clojure.core/count
floor fluree.db.query.exec.eval/floor
groupconcat fluree.db.query.exec.eval/groupconcat
in fluree.db.query.exec.eval/in
lang fluree.db.query.exec.eval/lang
lcase fluree.db.query.exec.eval/lcase
median fluree.db.query.exec.eval/median
Expand Down
2 changes: 1 addition & 1 deletion src/clj/fluree/db/query/exec/update.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
where/get-datatype-iri
(->> (generate-sid! db-vol)))
(dbproto/-p-prop @db-vol :datatype p-iri)
(datatype/infer v (:lang m)))
(datatype/infer v))
v* (datatype/coerce-value v dt)]
(flake/create sid pid v* dt t true m)))

Expand Down
27 changes: 0 additions & 27 deletions src/clj/fluree/db/query/exec/where.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -533,20 +533,6 @@
(dataset/activate alias)
(match-clause fuel-tracker solution clause error-ch)))

(defmethod match-pattern :exists
[ds fuel-tracker solution pattern error-ch]
(let [clause (pattern-data pattern)]
(go
(when (async/<! (match-clause ds fuel-tracker solution clause error-ch))
solution))))

(defmethod match-pattern :not-exists
[ds fuel-tracker solution pattern error-ch]
(let [clause (pattern-data pattern)]
(go
(when-not (async/<! (match-clause ds fuel-tracker solution clause error-ch))
solution))))

(defmethod match-pattern :graph
[ds fuel-tracker solution pattern error-ch]
(let [[g clause] (pattern-data pattern)]
Expand Down Expand Up @@ -580,19 +566,6 @@
clause-ch)
out-ch))

(defmethod match-pattern :values
[db fuel-tracker solution pattern error-ch]
(let [inline-solutions (pattern-data pattern)
;; transform a match into its identity for equality checks
match-identity (juxt get-iri get-value get-datatype-iri (comp get-meta :lang))
solution* (update-vals solution match-identity)]
;; filter out any inline solutions whose matches don't match the solution's matches
(->> inline-solutions
(filterv (fn [inline-solution] (= (select-keys solution* (keys inline-solution))
(update-vals inline-solution match-identity))))
(mapv (partial merge solution) inline-solutions)
(async/to-chan!))))

(defn with-default
"Return a transducer that transforms an input stream of solutions to include the
`default-solution` if and only if the stream was empty."
Expand Down
37 changes: 10 additions & 27 deletions src/clj/fluree/db/query/fql/parse.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@
(json-ld/expand-iri context)
(where/anonymous-value dt-iri))
(where/anonymous-value v dt-iri))
(if-let [lang (get attrs const/iri-language)]
(where/anonymous-value v const/iri-lang-string {:lang lang})
(where/anonymous-value v))))
(where/anonymous-value v)))

(defn parse-value-attributes
[v attrs context]
Expand All @@ -81,10 +79,8 @@
(let [expanded (json-ld/expand-iri val context)]
(where/match-iri var-match expanded))
(where/match-value var-match val dt-iri))
(if-let [lang (get attrs const/iri-language)]
(where/match-value var-match val const/iri-lang-string {:lang lang})
(let [dt (datatype/infer-iri val)]
(where/match-value var-match val dt))))))
(let [dt (datatype/infer-iri val)]
(where/match-value var-match val dt)))))

(defn match-value-binding
[var-match value context]
Expand All @@ -102,11 +98,11 @@
(zipmap vars binding)))

(defn parse-values
[values context]
(when values
[q context]
(when-let [values (:values q)]
(let [[vars vals] values
vars* (keep parse-var-name (util/sequential vars))
vals* (mapv util/sequential vals)
vars* (keep parse-var-name (util/sequential vars))
vals* (mapv util/sequential vals)
var-count (count vars*)]
(if (every? (fn [binding]
(= (count binding) var-count))
Expand Down Expand Up @@ -412,19 +408,6 @@
(let [parsed (parse-bind-map binds)]
[(where/->pattern :bind parsed)]))

(defmethod parse-pattern :values
[[_ values] vars context]
(let [[_vars solutions] (parse-values values context)]
[(where/->pattern :values solutions)]))

(defmethod parse-pattern :exists
[[_ patterns] vars context]
[(where/->pattern :exists (parse-where-clause patterns vars context))])

(defmethod parse-pattern :not-exists
[[_ patterns] vars context]
[(where/->pattern :not-exists (parse-where-clause patterns vars context))])

(defmethod parse-pattern :graph
[[_ graph where] vars context]
(let [graph* (or (parse-variable graph)
Expand Down Expand Up @@ -587,7 +570,7 @@
(defn parse-analytical-query
[q]
(let [context (context/extract q)
[vars values] (parse-values (:values q) context)
[vars values] (parse-values q context)
where (parse-where q vars context)
grouping (parse-grouping q)
ordering (parse-ordering q)]
Expand Down Expand Up @@ -701,8 +684,8 @@

(defn parse-txn
[txn context]
(let [values (util/get-first-value txn const/iri-values)
[vars values] (parse-values values context)
(let [vals-map {:values (util/get-first-value txn const/iri-values)}
[vars values] (parse-values vals-map context)
where-map {:where (util/get-first-value txn const/iri-where)}
where (parse-where where-map vars context)
bound-vars (-> where where/bound-variables (into vars))
Expand Down
Loading

0 comments on commit 16a7cc2

Please sign in to comment.