Skip to content

Commit

Permalink
refactor: start to split the logic of fetch from index step
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Aug 9, 2024
1 parent 69c2df8 commit 5fd3bc5
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 93 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.orientechnologies.orient.core.sql.executor;

import com.orientechnologies.common.util.ORawPair;
import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.index.OIndexInternal;
import java.util.stream.Stream;

class OAllIndexStream implements OIndexStream {
private OIndexInternal index;
private boolean asc;

public OAllIndexStream(OIndexInternal index, boolean asc) {
super();
this.index = index;
this.asc = asc;
}

public Stream<ORawPair<Object, ORID>> start(OCommandContext ctx) {
if (asc) {
return index.stream();
} else {
return index.descStream();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.orientechnologies.orient.core.sql.executor;

import com.orientechnologies.common.util.ORawPair;
import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.index.OIndexInternal;
import java.util.stream.Stream;

public class OBetweenIndexStream implements OIndexStream {
private OIndexInternal index;
private Object startKey;
private boolean includeStart;
private Object endKey;
private boolean includeEnd;
private boolean asc;

public OBetweenIndexStream(
OIndexInternal index,
Object startKey,
boolean includeStart,
Object endKey,
boolean includeEnd,
boolean asc) {
super();
this.index = index;
this.startKey = startKey;
this.includeStart = includeStart;
this.endKey = endKey;
this.includeEnd = includeEnd;
this.asc = asc;
}

public Stream<ORawPair<Object, ORID>> start(OCommandContext ctx) {
return index.streamEntriesBetween(startKey, includeStart, endKey, includeEnd, asc);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.orientechnologies.orient.core.sql.executor;

import com.orientechnologies.common.util.ORawPair;
import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.index.OIndexInternal;
import java.util.Collection;
import java.util.stream.Stream;

public class OExactIndexStream implements OIndexStream {
private OIndexInternal index;
private Collection<Object> startKey;
private boolean asc;

public OExactIndexStream(OIndexInternal index, Collection<Object> startKey, boolean asc) {
super();
this.index = index;
this.startKey = startKey;
this.asc = asc;
}

public Stream<ORawPair<Object, ORID>> start(OCommandContext ctx) {
return index.streamEntries(startKey, asc);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.orientechnologies.orient.core.sql.executor;

import com.orientechnologies.common.util.ORawPair;
import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.id.ORID;
import java.util.stream.Stream;

public interface OIndexStream {
public Stream<ORawPair<Object, ORID>> start(OCommandContext ctx);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.orientechnologies.orient.core.sql.executor;

import com.orientechnologies.common.util.ORawPair;
import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.index.OIndexInternal;
import java.util.stream.Stream;

public class OMajorIndexStream implements OIndexStream {
private OIndexInternal index;
private Object startKey;
private boolean include;
private boolean asc;

public OMajorIndexStream(OIndexInternal index, Object startKey, boolean include, boolean asc) {
super();
this.index = index;
this.startKey = startKey;
this.include = include;
this.asc = asc;
}

public Stream<ORawPair<Object, ORID>> start(OCommandContext ctx) {
return index.streamEntriesMajor(startKey, include, asc);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.orientechnologies.orient.core.sql.executor;

import com.orientechnologies.common.util.ORawPair;
import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.index.OIndexInternal;
import java.util.stream.Stream;

public class OMinorIndexStream implements OIndexStream {
private OIndexInternal index;
private Object startKey;
private boolean include;
private boolean asc;

public OMinorIndexStream(OIndexInternal index, Object startKey, boolean include, boolean asc) {
super();
this.index = index;
this.startKey = startKey;
this.include = include;
this.asc = asc;
}

public Stream<ORawPair<Object, ORID>> start(OCommandContext ctx) {
return index.streamEntriesMinor(startKey, include, asc);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.orientechnologies.orient.core.sql.executor;

import com.orientechnologies.common.util.ORawPair;
import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.index.OIndexInternal;
import java.util.stream.Stream;

public class ONullIndexStream implements OIndexStream {
private OIndexInternal index;

public ONullIndexStream(OIndexInternal index) {
super();
this.index = index;
}

public Stream<ORawPair<Object, ORID>> start(OCommandContext ctx) {
final Stream<ORID> stream = index.getRids(null);
return stream.map((rid) -> new ORawPair<>(null, rid));
}
}

0 comments on commit 5fd3bc5

Please sign in to comment.