-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix GROUP_CONCAT losing languages if equal
- Loading branch information
1 parent
476a303
commit 0cf0bee
Showing
2 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
15 changes: 14 additions & 1 deletion
15
packages/expression-evaluator/lib/aggregators/GroupConcat.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,38 @@ | ||
import type * as RDF from '@rdfjs/types'; | ||
import { string } from '../functions/Helpers'; | ||
import { langString, string } from '../functions/Helpers'; | ||
import { AggregatorComponent } from './Aggregator'; | ||
|
||
export class GroupConcat extends AggregatorComponent { | ||
private state: string | undefined = undefined; | ||
private lastLanguageValid = true; | ||
private lastLanguage: string | undefined = undefined; | ||
|
||
public static emptyValue(): RDF.Term { | ||
return string('').toRDF(); | ||
} | ||
|
||
public put(term: RDF.Term): void { | ||
if (this.state === undefined) { | ||
this.state = term.value; | ||
if (term.termType === 'Literal') { | ||
this.lastLanguage = term.language; | ||
} | ||
} else { | ||
this.state += this.separator + term.value; | ||
if (this.lastLanguageValid && term.termType === 'Literal' && this.lastLanguage !== term.language) { | ||
this.lastLanguageValid = false; | ||
this.lastLanguage = undefined; | ||
} | ||
} | ||
} | ||
|
||
public result(): RDF.Term { | ||
if (this.state === undefined) { | ||
return GroupConcat.emptyValue(); | ||
} | ||
if (this.lastLanguageValid && this.lastLanguage) { | ||
return langString(this.state, this.lastLanguage).toRDF(); | ||
} | ||
return string(this.state).toRDF(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters