Repository navigation
Decision: translate UNION as a bag union of arms and give differently shaped terms their own columns #60
Replies: 1 comment
Addendum: OPTIONAL parts that several choices can match (second pull request for #51)Discussion #55 rejected an Decision
Results
추가: 여러 선택이 맞을 수 있는 OPTIONAL 부분(#51 두 번째 PR)Discussion #55는 트리플 맵 조합 여러 개가 맞을 수 있는 결정
결과
|
Uh oh!
There was an error while loading. Please reload this page.
Background
{ A } UNION { B }is the SPARQL algebra's Union: the solutions of both sides as a bag (SPARQL 1.1 Query, 18.5 SPARQL Algebra, Definition: Union). A solution that both sides give counts twice, and a variable bound on one side only is unbound in the other side's solutions. Discussion #41 made every basic graph pattern a set of solutions (graph set semantics), deduplicated once per query over the columns of all variables; Discussion #55 introduced the pattern tree,LEFT JOINparts and variables with several sources chosen while building results.The engine already combined SQL branches with
UNION: one branch per choice of triples maps for the required triple patterns, all deduplicated together. A query-levelUNIONmust not be deduplicated across its sides, must compose withOPTIONALandFILTERscope (Discussion #57), and brings the problem of #29 to the front: a variable whose term maps differ in shape across branches (a template in one, a column or another template in the other, constants, IRIs against literals, datatypes, language tags) was rejected, because the result rows did not say which term map built them.Decision
UNION as a bag union of arms
sparql::parsekeepsUnion(left, right). Join, Filter and the left side of LeftJoin distribute over a union (18.5: Join, Filter and LeftJoin are defined pointwise over the solutions of their left operand), so the pattern is the bag union of its arms, each a choice of one side of everyUnionoutside the right side of every LeftJoin. Each arm is unfolded like a union-free pattern; its branches carry the arm (SqlBranch::arm).DISTINCTfor one branch,UNIONacross its branches. The arms are combined withUNION ALL, parenthesized where an arm has several branches:(b1 UNION b2) UNION ALL b3. UnderSELECT DISTINCTall branches form oneUNION.{ ?x ex:city ?y } UNION { ?x ex:amount ?a }over keyed tables is two plainSELECTs joined byUNION ALL, indexes intact.FILTERinside one side is in that side's group and compiled against its variables only; aFILTERof the group around the union applies to the solutions of both sides, where the other side's variables are unbound (an error, except forBOUND), as Discussion Decision: encode FILTER errors as SQL NULL and compare by the SPARQL operator mapping #57 defines.MAX_BRANCHES), as before.Variables of differently shaped term maps (#29)
NULL, and the results take the first bound term, the mechanism Decision: translate OPTIONAL to nested LEFT JOINs translated part by part #55 introduced for severalOPTIONALparts. A constant shape that some rows do not bind gets a flag column (true/ typedNULL).term_eqisNever): different term types, different literal datatypes or language tags, different constants, templates whose fixed prefixes or suffixes differ, and, new, IRI templates where one has fixed text with a character that IRI-safe encoding always escapes in the other's values and the other's fixed text lacks (http://example.com/{ID}/{First};{Last}againsthttp://example.com/{ID}/{Description}: a value renders;as%3B). This rule also drops join branches that can never match.DISTINCT, are merged into one result column holding the term's string computed in SQL, with the same rendering as joins (SqlExpr::Term: IRI-safe template, base-IRI resolution, natural lexical forms from column types). The result is rebuilt from that string with the shared term type, datatype or language tag. The same IRI fromhttp://example.org/customer/{id}and from an IRI column then counts once, as Ontop answers.float8, date/time).SELECT DISTINCTover a variable bound by more than oneOPTIONALpart stays rejected (Discussion Decision: translate OPTIONAL to nested LEFT JOINs translated part by part #55).Results
Differential tests: a new case
tests/diff/0007-union(25 queries: unions of classes, variables unbound in one side, duplicates across sides with and withoutDISTINCT, nested unions, a pattern joined after a union,FILTERinside a side and around the union,OPTIONALinside a union, a union insideOPTIONAL,SELECT *, and #29 shapes: disjoint templates, a template against an IRI column repeating its IRIs, a hidden variable over both, constants, IRI against literal, language tags, datatypes) matches Ontop in 23 queries; 2 are rejected by design (a union insideOPTIONALwhose both sides match, until the second pull request; overlapping literals of a natural datatype). The W3C casesR2RMLTC0011a/idandR2RMLTC0015a/label, rejected under #29 so far, now match Ontop. All 218 queries pass: 193 match Ontop (up from 168 of 193), 10 known mismatches, 6 Ontop errors, 9 rejected.References
배경
{ A } UNION { B }는 SPARQL algebra의 Union이다. 두 쪽의 solution을 bag으로 합친다(SPARQL 1.1 Query, 18.5 SPARQL Algebra, Definition: Union). 두 쪽이 같은 solution을 주면 두 번 세고, 한쪽에서만 바인딩되는 변수는 다른 쪽 solution에서 unbound다. Discussion #41은 basic graph pattern을 solution의 집합으로 만들었고(그래프 집합 의미), 질의마다 모든 변수의 컬럼으로 한 번 중복을 제거한다. Discussion #55는 패턴 트리,LEFT JOIN부분, 결과를 만들 때 고르는 여러 출처의 변수를 들였다.엔진은 이미 SQL 가지를
UNION으로 합치고 있었다. 필수 트리플 패턴마다 트리플 맵을 고르는 조합 하나가 가지 하나이고, 모두 함께 중복을 제거했다. 질의의UNION은 두 쪽 사이에서 중복을 제거하면 안 되고,OPTIONAL,FILTER범위(Discussion #57)와 함께 맞물려야 한다. 그리고 #29 문제가 앞으로 나온다. 가지마다 텀 맵 모양이 다른 변수(한쪽은 템플릿, 다른 쪽은 컬럼이나 다른 템플릿, 상수, IRI와 리터럴, datatype, 언어 태그)는 결과 행이 어느 텀 맵에서 왔는지 모르기 때문에 거절됐다.결정
UNION은 arm들의 bag 합집합
sparql::parse가Union(left, right)를 유지한다. Join, Filter, LeftJoin의 왼쪽은 union에 분배된다(18.5: Join, Filter, LeftJoin은 왼쪽 피연산자의 solution마다 정의된다). 그래서 패턴은 arm들의 bag 합집합이다. arm은 모든 LeftJoin 오른쪽 바깥의Union마다 한쪽을 고른 것이다. arm마다 union 없는 패턴처럼 unfold하고, 그 가지에 arm을 기록한다(SqlBranch::arm).DISTINCT, 여러 가지면UNION이다. arm끼리는UNION ALL로 합치고, 가지가 여러 개인 arm은 괄호로 묶는다:(b1 UNION b2) UNION ALL b3.SELECT DISTINCT에서는 모든 가지가 하나의UNION이다.{ ?x ex:city ?y } UNION { ?x ex:amount ?a }는UNION ALL로 이은 평범한SELECT둘이고 인덱스도 그대로 쓴다.FILTER는 그쪽 그룹에 속하고 그쪽 변수로만 컴파일한다. union을 감싼 그룹의FILTER는 두 쪽 solution 모두에 적용되고, 다른 쪽 변수는 unbound다(BOUND를 빼면 오류). Discussion #57의 정의 그대로다.MAX_BRANCHES)로 제한한다.텀 맵 모양이 다른 변수(#29)
NULL로 둔다. 결과는 처음으로 바인딩된 텀을 쓴다. #55가 여러OPTIONAL부분에 쓰려고 들인 방식이다. 일부 행이 바인딩하지 않는 상수 모양에는 플래그 컬럼(true/ 타입 붙은NULL)을 둔다.term_eq가Never) 두 모양은 서로소다. 텀 타입이 다르거나, 리터럴 datatype이나 언어 태그가 다르거나, 상수가 다르거나, 템플릿의 고정 접두사나 접미사가 다른 경우, 그리고 새로 넣은 규칙으로 한 IRI 템플릿의 고정 텍스트에 다른 템플릿 값에서는 IRI-safe 인코딩이 언제나 이스케이프하는 문자가 있고 다른 템플릿의 고정 텍스트에는 그 문자가 없는 경우다(http://example.com/{ID}/{First};{Last}와http://example.com/{ID}/{Description}: 값의;는%3B가 된다). 이 규칙은 절대 맞을 수 없는 조인 가지도 없앤다.DISTINCT에서는 모든 가지)은 SQL로 계산한 텀 문자열을 담는 결과 컬럼 하나로 합친다. 렌더링은 조인과 같다(SqlExpr::Term: IRI-safe 템플릿, base IRI 해석, 컬럼 타입에 따른 자연 어휘형). 결과는 그 문자열과 공통 텀 타입, datatype, 언어 태그로 다시 만든다.http://example.org/customer/{id}와 IRI 컬럼이 같은 IRI를 주면 한 번 센다. Ontop의 답과 같다.float8, 날짜/시간).OPTIONAL부분이 바인딩하는 변수에 대한SELECT DISTINCT는 계속 거절한다(Discussion Decision: translate OPTIONAL to nested LEFT JOINs translated part by part #55).결과
차등 테스트: 새 케이스
tests/diff/0007-union(25개 질의: 클래스의 union, 한쪽에서 unbound인 변수,DISTINCT유무에 따른 두 쪽 사이의 중복, 중첩 union, union 뒤에 조인하는 패턴, 한쪽 안과 union 바깥의FILTER, union 안의OPTIONAL,OPTIONAL안의 union,SELECT *, 그리고 #29 모양: 서로소 템플릿, 템플릿 IRI를 다시 담은 IRI 컬럼, 둘에 걸친 숨은 변수, 상수, IRI와 리터럴, 언어 태그, datatype)는 23개 질의에서 Ontop과 같고, 2개는 설계상 거절한다(두 쪽이 모두 맞는OPTIONAL안의 union은 두 번째 PR까지, 자연 datatype의 겹칠 수 있는 리터럴). 지금까지 #29로 거절하던 W3C 케이스R2RMLTC0011a/id,R2RMLTC0015a/label이 이제 Ontop과 같다. 218개 질의가 모두 통과한다: Ontop과 같음 193(193개 중 168에서 증가), 알려진 차이 10, Ontop 오류 6, 거절 9.참고
All reactions