Skip to content

Commit

Permalink
chore: handle pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ajuvercr committed Oct 15, 2024
1 parent 672518e commit a84d0c7
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 22 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,8 @@ When a member arrives, all buckets that hold members with a timestamp older than
tree:timestampPath <http://def.isotc211.org/iso19156/2011/Observation#OM_Observation.resultTime>;
tree:buffer 5000; # members can arrive 5 seconds out of sync ()
tree:level ( [ # Create 5 levels, resulting uri's <year>/<month>/<day>/<hour>/<minute>
tree:range "year";
tree:range "year", "month";
tree:maxSize 0; # place no members at this level
] [
tree:range "month";
tree:maxSize 0; # place no members at this level
] [
tree:range "day-of-month";
tree:maxSize 1000; # place at most 1000 members at this level
Expand All @@ -135,6 +132,8 @@ When a member arrives, all buckets that hold members with a timestamp older than
] ).
```

This fragmentation will look like this `${year}-${month}/${day}/${hour}/${minute}` after ingesting 2001 members in the same hour (filling day and hour).


### [`js:Ldesify`](https://github.com/rdf-connect/sds-processors/blob/master/configs/ldesify.ttl#L10)

Expand Down
4 changes: 2 additions & 2 deletions configs/bucketizer_configs.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
].

[ ] a sh:NodeShape;
sh:targetClass tree:timeBucket;
sh:targetClass tree:TimeBucketLevel;
sh:property [
sh:name "ranges";
sh:path tree:range;
Expand Down Expand Up @@ -141,7 +141,7 @@
], [
sh:name "levels";
sh:path tree:level;
sh:class tree:timeBucket;
sh:class tree:TimeBucketLevel;
sh:minCount 1;
], [
sh:name "timeBufferMs";
Expand Down
1 change: 0 additions & 1 deletion src/bucketizers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ export async function bucketize(
newMembers,
newRelations,
prefix,
// sourceStream?.value || "/",
);

record_buckets.forEach((x) => requestedBuckets.add(x));
Expand Down
22 changes: 11 additions & 11 deletions src/bucketizers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import SubjectBucketizer from "./subjectBucketizer";
import TimebasedBucketizer from "./timebasedBucketizer";

import { $INLINE_FILE } from "@ajuvercr/ts-transformer-inline-file";
import TimeBucketTreeBucketizer, {
TimeBucketTreeConfig,
} from "./timeBucketTree";
import TimeBucketBucketizer, { TimeBucketTreeConfig } from "./timeBucketTree";

export { TimeBucketTreeConfig } from "./timeBucketTree";

Expand Down Expand Up @@ -86,14 +84,22 @@ function createBucketizer(config: BucketizerConfig, save?: string): Bucketizer {
save,
);
case TREE.custom("TimeBucketFragmentation"):
return new TimeBucketTreeBucketizer(
return new TimeBucketBucketizer(
<TimeBucketTreeConfig>config.config,
save,
);
}
throw "Unknown bucketizer " + config.type.value;
}

function combineIds(id1: string, id2: string) {
const id1Slash = id1.endsWith("/");
const id2Slash = id1.startsWith("/");
if (id1Slash && id2Slash) return id1 + id2.slice(1);
if (id1 === "" || id1Slash || id2Slash) return id1 + id2;
return id1 + "/" + id2;
}

export class BucketizerOrchestrator {
private readonly configs: BucketizerConfig[];

Expand Down Expand Up @@ -158,16 +164,10 @@ export class BucketizerOrchestrator {
const key = value.endsWith("/")
? encodedValue
: encodedValue + "/";
// const key = value;
// If the requested bucket is the root, it actually is the previous bucket

// avoid double slashes and leading slashes
const next =
prefix.endsWith("/") ||
prefix == "" ||
key.startsWith("/")
? prefix + key
: prefix + "/" + key;
const next = combineIds(prefix, key);
const id = root ? prefix : next;
if (!buckets[id]) {
buckets[id] = new Bucket(df.namedNode(id), [], false);
Expand Down
9 changes: 5 additions & 4 deletions src/bucketizers/timeBucketTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ function hydrate(state: State) {
}
}

export default class TimeBucketTreeBucketizer implements Bucketizer {
export default class TimeBucketBucketizer implements Bucketizer {
private readonly config: TimeBucketTreeConfig;
private readonly path: BasicLensM<Cont, { value: string; literal?: Term }>;
private readonly state: State = {};
Expand Down Expand Up @@ -291,7 +291,7 @@ export default class TimeBucketTreeBucketizer implements Bucketizer {
const found = goInState(state, levelValue, date, lastF);

state = found.value.deep;
key = concat_key(key, levelValue);
key = concatKey(key, levelValue);

const nextBucket = getBucket(key);
if (!found.found) {
Expand All @@ -314,6 +314,7 @@ export default class TimeBucketTreeBucketizer implements Bucketizer {
this.config.pathQuads,
);
}

bucket = nextBucket;
if (found.value.count < level.amount) {
found.value.count += 1;
Expand All @@ -332,7 +333,7 @@ export default class TimeBucketTreeBucketizer implements Bucketizer {
}
}

function concat_key(path: string, key: string): string {
function concatKey(path: string, key: string): string {
if (path.length === 0) {
return key;
} else {
Expand All @@ -349,7 +350,7 @@ function checkImmutable(
for (const key of Object.keys(state)) {
const inner = state[key];
if (!inner.immutable && inner.end < end) {
const innerPath = concat_key(path, key);
const innerPath = concatKey(path, key);
const bucket = getBucket(innerPath);
inner.immutable = true;
bucket.immutable = true;
Expand Down

0 comments on commit a84d0c7

Please sign in to comment.