Repository navigation
Decision: keep literal comparisons exact where SQL = is coarser, and lower-case language tags #65
CharmingGroot
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Background
Issue #53 (V5, step 5) reviews typed and language-tagged literals across triple patterns, joins,
FILTER,ORDER BY, removing duplicates and results, against RDF 1.1 term equality (RDF 1.1 Concepts §3.3) and SPARQL 1.1 (§2.3 Matching RDF Literals, §17.3 Operator Mapping, §17.4.1.7 RDFterm-equal). Discussions #21, #35 and #57 already decided that constants and joins compare RDF terms, that results use XSD 1.1 canonical forms, and howFILTERcompares values. The review found three gaps:=is coarser than term equality for two column types. Inrealanddouble precision,-0 = 0holds, while the engine writes-0.0E0and0.0E0(XSD 1.1doubleCanonicalMap), two different terms. Inchar(n),=ignores trailing spaces, while values keep their padding ('a'::char(3)is"a "). So the constant"0.0E0"^^xsd:doublematched rows holding-0(Do not match a 0.0E0 double constant against -0 rows #59), achar(3)column matched the constant"a"and joined achar(5)column, andSELECT DISTINCTreturned one of-0.0E0and0.0E0, dropping a solution, which Discussion Decision: count each triple once, keep bag semantics for solutions #41 ruled out ("over-counting only, never dropping a solution"). Joins between float columns were already exact: they compare the text output (Discussion Decision: emit XSD 1.1 canonical lexical forms #35).rr:languagewas not. Two term maps withrr:language "EN-us"and"en-US"for one variable were rejected as unsupported, and an invalid tag only failed when a row was turned into a term.rr:constant) failed witherror deserializing column 0: the placeholderSELECT 1column moved the row count.Decision
A term key next to
==and add a key that tells the remaining values apart:col = $1 AND key(col) = key($1). The key isx::textfor floating point (the sign of a zero) andoctet_length(x)forbpchar(the padding).=stays first, so an index on the column still finds the candidates and the key only filters them (PostgreSQL 17:Index Cond: (f = '0'::double precision),Filter: ((f)::text = '0'::text)).RenderOptions::keyed_params): float parameters only for a zero constant, since other float values are equal exactly when their terms are; everybpcharparameter.INlists (Discussion Decision: resolve relative IRIs against a configured base IRI, with no default #48) compare the key of every alternative.bpcharcolumns comparea = b AND octet_length(a) = octet_length(b)(ColumnType::term_key).DISTINCTandUNIONcompare values with=. When a query removes duplicates (underDISTINCT, or when keys do not prove there are none, Discussion Decision: count each triple once, keep bag semantics for solutions #41), the adapter now also reads the types of every selected column, one more probe statement for those queries only, and selects the key of each float orbpcharcolumn next to it inside the deduplicating subquery. The outer query leaves the keys out of the results.sameTermoverrealanddouble precisioncolumns, rejected in Discussion Decision: encode FILTER errors as SQL NULL and compare by the SPARQL operator mapping #57 because of-0, is supported through the same keys.=on numbers is unchanged: XPath'sop:numeric-equalfinds-0equal to0.v12n explainhas no database and shows the SQL without keys, as it showsDISTINCTwithout key metadata.Language tags
rr:languageis kept in lower case when the mapping is loaded, the form constants and results already have. Two term maps whose tags differ only in case have one shape, soUNION,DISTINCTand joins treat their terms as one.v12n check(exit code 2) instead of failing per row at query time. W3C test R2RMLTC0015b expects such a mapping to be rejected (not vendored: it has no expected output).rr:datatype rdf:langStringis a mapping error: RDF 1.1 Concepts §3.3 gives every literal of that datatype a language tag, so a term map without one cannot produce it.Confirmed, unchanged
xsd:stringliteral everywhere: constants with and without^^xsd:string, a text column, a column withrr:datatype xsd:stringand a literal template give the same term,DATATYPEreturnsxsd:string, and results write it without a datatype."5"^^xsd:intagainst an integer column, a custom datatype): term equality, SPARQL 1.1 §2.3.3. InFILTER, where numbers compare by value,xsd:floatand the derived integer types stay rejected (Discussion Decision: encode FILTER errors as SQL NULL and compare by the SPARQL operator mapping #57).FILTER=,LANG,sameTermandORDER BYalready compared tags in lower case.To review
bpchar: for the other decoded types=agrees with term equality (numericthrough the canonical decimal,timestamptznormalized to UTC). Text columns with a nondeterministic collation, whose=can ignore case, are not handled.char(n)literals keep their padding, as before, while PostgreSQL's cast to text drops it.Results
Differential tests: a new case
tests/diff/0009-literals(24 queries: tags in another case in constants,FILTER =,LANG,sameTerm, joins andDISTINCT;xsd:stringfrom three term maps and constants; constants of datatypes the columns never give) matches Ontop in 23; 1 is the recorded canonical-double difference (#25). All 282 queries pass: 256 match Ontop (up from 233 of 258), 13 known mismatches, 6 Ontop errors, 7 rejected. Database tests cover what the differential cases do not: zero constants with the index,-0and0in joins,DISTINCT,UNIONand IRIs,char(n)padding, tags across two term maps, and a projection of constant terms.References
rdf:langString) — https://www.w3.org/TR/rdf11-concepts/배경
이슈 #53(V5 5단계)은 트리플 패턴, 조인,
FILTER,ORDER BY, 중복 제거, 결과 전반에서 typed·언어 태그 리터럴을 RDF 1.1의 term 동등(RDF 1.1 Concepts §3.3)과 SPARQL 1.1(§2.3 Matching RDF Literals, §17.3 Operator Mapping, §17.4.1.7 RDFterm-equal) 기준으로 점검한다. 상수와 조인이 RDF term을 비교한다는 것, 결과가 XSD 1.1 canonical 형태를 쓴다는 것,FILTER가 값을 비교하는 방식은 Discussion #21, #35, #57에서 이미 정했다. 점검에서 빈틈 세 가지가 나왔다.=가 term 동등보다 느슨하다.real과double precision에서는-0 = 0이 참이지만 엔진은-0.0E0과0.0E0(XSD 1.1doubleCanonicalMap)을 내고, 이 둘은 다른 term이다.char(n)에서는=가 뒤쪽 공백을 무시하지만 값은 채움 공백을 그대로 갖는다('a'::char(3)은"a "). 그래서 상수"0.0E0"^^xsd:double이-0행과도 일치했고(Do not match a 0.0E0 double constant against -0 rows #59),char(3)컬럼이 상수"a"와 일치하고char(5)컬럼과 조인됐으며,SELECT DISTINCT가-0.0E0과0.0E0중 하나만 내서 해를 하나 잃었다. Discussion #41은 "많이 세는 쪽만 허용하고 해를 잃지 않는다"고 정했다. float 컬럼 사이의 조인은 텍스트 출력을 비교하므로(Discussion Decision: emit XSD 1.1 canonical lexical forms #35) 이미 정확했다.rr:language는 아니었다. 한 변수에rr:language "EN-us"와"en-US"인 term map 두 개가 있으면 미지원으로 거절됐고, 잘못된 태그는 행을 term으로 만들 때에야 실패했다.rr:constant)만 투영하는 질의가error deserializing column 0으로 실패했다. 자리 표시용SELECT 1컬럼 때문에 행 수 컬럼 위치가 밀렸다.결정
=옆에 term 키=를 그대로 두고, 남은 값을 구분하는 키를 더한다:col = $1 AND key(col) = key($1). 키는 부동소수점이면x::text(0의 부호),bpchar이면octet_length(x)(채움 공백)다.=가 앞에 있으므로 컬럼 인덱스로 후보를 찾고 키는 거르기만 한다(PostgreSQL 17:Index Cond: (f = '0'::double precision),Filter: ((f)::text = '0'::text)).RenderOptions::keyed_params). float 파라미터는 상수가 0일 때만이다. 다른 float 값은 값이 같으면 term도 같기 때문이다.bpchar파라미터는 항상이다.IN목록(Discussion Decision: resolve relative IRIs against a configured base IRI, with no default #48)은 모든 대안의 키를 비교한다.bpchar컬럼 둘은a = b AND octet_length(a) = octet_length(b)로 비교한다(ColumnType::term_key).DISTINCT와UNION은 값을=로 비교한다. 질의가 중복을 제거할 때(DISTINCT이거나, 키로 중복 없음을 증명하지 못할 때, Discussion Decision: count each triple once, keep bag semantics for solutions #41) 어댑터는 선택하는 모든 컬럼의 타입도 읽는다. 이런 질의에서만 probe 문장이 하나 늘어난다. float나bpchar컬럼마다 그 키를 중복 제거 서브쿼리에서 함께 선택하고, 바깥 질의는 키를 결과에서 뺀다.-0때문에 거절했던 **real·double precision컬럼의sameTerm**은 같은 키로 지원한다. 숫자의=는 그대로다. XPathop:numeric-equal에서-0과0은 같다.v12n explain은 DB가 없으므로 키 없는 SQL을 보여 준다. 키 메타데이터 없이DISTINCT를 보여 주는 것과 같다.언어 태그
rr:language는 매핑을 읽을 때 소문자로 둔다. 상수와 결과가 이미 쓰는 형태다. 대소문자만 다른 태그의 term map 두 개는 같은 모양이 되어UNION,DISTINCT, 조인이 그 term을 하나로 다룬다.v12n check가 알린다(종료 코드 2). W3C 테스트 R2RMLTC0015b도 이런 매핑을 거절하길 기대한다(기대 출력이 없어 저장소에는 넣지 않았다).rr:datatype rdf:langString은 매핑 오류다. RDF 1.1 Concepts §3.3에 따라 그 datatype의 리터럴은 언어 태그가 반드시 있으므로, 태그가 없는 term map은 그런 리터럴을 만들 수 없다.확인했고 바꾸지 않은 것
xsd:string리터럴이다.^^xsd:string이 있든 없든 상수, 텍스트 컬럼,rr:datatype xsd:string컬럼, 리터럴 템플릿이 같은 term을 내고,DATATYPE은xsd:string을 돌려주며, 결과는 datatype 없이 쓴다."5"^^xsd:int, 사용자 정의 datatype). term 동등, SPARQL 1.1 §2.3.3이다. 숫자를 값으로 비교하는FILTER에서는xsd:float과 파생 정수 타입을 계속 거절한다(Discussion Decision: encode FILTER errors as SQL NULL and compare by the SPARQL operator mapping #57).FILTER의=,LANG,sameTerm,ORDER BY는 이미 태그를 소문자로 비교했다.검토할 점
bpchar에만 둔다. 다른 디코딩 타입은=가 term 동등과 맞는다(numeric은 canonical decimal,timestamptz는 UTC 정규화).=가 대소문자를 무시할 수 있는 nondeterministic collation의 텍스트 컬럼은 다루지 않는다.char(n)리터럴은 이전처럼 채움 공백을 유지한다. PostgreSQL의 text 변환은 공백을 지운다.결과
차등 테스트: 새 케이스
tests/diff/0009-literals(24개 질의: 대소문자가 다른 태그의 상수,FILTER =,LANG,sameTerm, 조인,DISTINCT; term map 세 종류와 상수에서 나온xsd:string; 컬럼이 내지 않는 datatype의 상수)는 23개가 Ontop과 일치하고, 1개는 기록된 canonical double 차이(#25)다. 전체 282개 질의 통과: 256개 Ontop 일치(258개 중 233개에서 증가), 알려진 불일치 13, Ontop 오류 6, 거절 7. 차등 케이스가 다루지 않는 부분은 DB 테스트가 맡는다: 인덱스를 쓰는 0 상수, 조인·DISTINCT·UNION·IRI에서의-0과0,char(n)채움 공백, term map 두 개에 걸친 태그, 상수 term 투영.참고
rdf:langString) — https://www.w3.org/TR/rdf11-concepts/All reactions