-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] Filter Criteria for Late Filtering #123
Merged
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
5ef6651
adds simple filter operators
net-cscience-raphael 01552f5
adds null safety for values
net-cscience-raphael 33e3db5
formats
net-cscience-raphael e04f14e
adds append to late filter
net-cscience-raphael 6713af4
Debugs like and adds Assertions.assertTrue(result.isNotEmpty()) to test
net-cscience-raphael 3b5ab2f
adds like for query LateFilter
net-cscience-raphael 4b8292d
adds late limit
net-cscience-raphael a75268d
disables again assertion for 0 results
net-cscience-raphael 1ee7ec2
changes name for filter transformer
net-cscience-raphael 0dfa5f0
Adds Late filter without lookup
net-cscience-raphael 77f2ed9
minor adjustments
net-cscience-raphael f803265
debugs skip strategy
net-cscience-raphael 572dc21
changes default
net-cscience-raphael 753014b
adjusts comments
net-cscience-raphael ba9a936
adds transformer for benchmark
net-cscience-raphael 98af3e2
draft logger
net-cscience-raphael e66b12e
adds simple filter operators
net-cscience-raphael 2ea8948
adds null safety for values
net-cscience-raphael 4721ed6
formats
net-cscience-raphael e46ef8d
adds append to late filter
net-cscience-raphael cf977ba
Debugs like and adds Assertions.assertTrue(result.isNotEmpty()) to test
net-cscience-raphael 85a8872
adds like for query LateFilter
net-cscience-raphael ee3cbe9
adds late limit
net-cscience-raphael 641e5df
disables again assertion for 0 results
net-cscience-raphael 9f39cba
changes name for filter transformer
net-cscience-raphael 6384b43
Adds Late filter without lookup
net-cscience-raphael c0cbd08
minor adjustments
net-cscience-raphael 1242c9d
debugs skip strategy
net-cscience-raphael 2b1fad0
changes default
net-cscience-raphael 25bd826
adjusts comments
net-cscience-raphael f67a1e5
adds transformer for benchmark
net-cscience-raphael cde944a
draft logger
net-cscience-raphael 0fb0adc
Merge remote-tracking branch 'origin/feature/filtercriteria' into fea…
net-cscience-raphael ade752c
Auto stash before rebase of "feature/filtercriteria" onto "origin/dev"
net-cscience-raphael 72f01a9
Merge branch 'feature/filtercriteria' into dev
net-cscience-raphael b3bfafb
Merge branch 'dev' into feature/filtercriteria
net-cscience-raphael 15bd7f6
adds Text type
net-cscience-raphael File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
35 changes: 35 additions & 0 deletions
35
...src/main/kotlin/org/vitrivr/engine/query/operators/transform/benchmark/BenchmarkLogger.kt
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.vitrivr.engine.query.operators.transform.benchmark | ||
|
||
import io.github.oshai.kotlinlogging.KLogger | ||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
import kotlinx.serialization.json.Json | ||
import kotlinx.serialization.json.encodeToJsonElement | ||
import java.io.* | ||
import java.nio.file.Path | ||
import java.util.concurrent.BlockingQueue | ||
import java.util.concurrent.LinkedBlockingQueue | ||
|
||
|
||
class BenchmarkLogger(val logfile: Path) : Runnable { | ||
private val logger: KLogger = KotlinLogging.logger {} | ||
|
||
private val queue: BlockingQueue<BenchmarkMessage> = LinkedBlockingQueue() | ||
|
||
infix fun log(message: BenchmarkMessage) { | ||
queue.add(message) | ||
} | ||
|
||
override fun run() { | ||
while (true) { | ||
|
||
val log = queue.take() | ||
logger.info { log } | ||
|
||
|
||
FileOutputStream(File(logfile.toString()), true).bufferedWriter().use { writer -> | ||
writer.appendLine("${Json.encodeToJsonElement(log).toString()},") | ||
writer.close() | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...rc/main/kotlin/org/vitrivr/engine/query/operators/transform/benchmark/BenchmarkMessage.kt
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.vitrivr.engine.query.operators.transform.benchmark | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class BenchmarkMessage ( | ||
val name: String, | ||
val source: String, | ||
val timestamp: String, | ||
val inputSize: Int, | ||
) |
54 changes: 54 additions & 0 deletions
54
...y/src/main/kotlin/org/vitrivr/engine/query/operators/transform/benchmark/TimeBenchmark.kt
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.vitrivr.engine.query.operators.transform.benchmark | ||
|
||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.emitAll | ||
import kotlinx.coroutines.flow.flow | ||
import kotlinx.coroutines.flow.toList | ||
import org.vitrivr.engine.core.database.descriptor.DescriptorReader | ||
import org.vitrivr.engine.core.model.metamodel.Schema | ||
import org.vitrivr.engine.core.model.retrievable.Retrievable | ||
import org.vitrivr.engine.core.model.retrievable.Retrieved | ||
import org.vitrivr.engine.core.model.retrievable.attributes.PropertyAttribute | ||
import org.vitrivr.engine.core.model.types.Value | ||
import org.vitrivr.engine.core.operators.Operator | ||
import org.vitrivr.engine.core.operators.general.Transformer | ||
import java.nio.file.Path | ||
import java.time.LocalDateTime | ||
import java.util.Timer | ||
import javax.management.Descriptor | ||
|
||
/** | ||
* Appends [Descriptor] to a [Retrieved] based on the values of a [Schema.Field], if available. | ||
* | ||
* @version 1.1.2 | ||
* @author Luca Rossetto | ||
* @author Ralph Gasser | ||
*/ | ||
class TimeBenchmark( | ||
override val input: Operator<out Retrievable>, | ||
val path: Path, | ||
val pretty: String, | ||
override val name: String | ||
) : Transformer { | ||
|
||
companion object { | ||
@Volatile | ||
private var bl: BenchmarkLogger? = null | ||
} | ||
|
||
init { | ||
if (bl == null) { | ||
bl = BenchmarkLogger(path) | ||
Thread(bl).start() | ||
} | ||
} | ||
|
||
override fun toFlow(scope: CoroutineScope): Flow<Retrievable> = flow { | ||
val inputRetrieved = input.toFlow(scope).toList() | ||
bl!! log BenchmarkMessage(name, pretty, LocalDateTime.now().toString(), inputRetrieved.size) | ||
inputRetrieved.forEach { emit(it) } | ||
} | ||
} | ||
|
||
|
17 changes: 17 additions & 0 deletions
17
...ain/kotlin/org/vitrivr/engine/query/operators/transform/benchmark/TimeBenchmarkFactory.kt
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.vitrivr.engine.query.operators.transform.benchmark | ||
|
||
import org.vitrivr.engine.core.context.Context | ||
import org.vitrivr.engine.core.context.QueryContext | ||
import org.vitrivr.engine.core.model.retrievable.Retrievable | ||
import org.vitrivr.engine.core.operators.Operator | ||
import org.vitrivr.engine.core.operators.general.TransformerFactory | ||
import kotlin.io.path.Path | ||
|
||
class TimeBenchmarkFactory() : TransformerFactory { | ||
override fun newTransformer(name: String, input: Operator<out Retrievable>, context: Context): TimeBenchmark { | ||
require(context is QueryContext) | ||
val logfilePath = Path(context[name, "logfile"]?.toString() ?: "benchmark.log") | ||
val prettyName = context[name, "pretty"]?.toString() ?: name | ||
return TimeBenchmark(input, logfilePath, prettyName, name) | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
.../main/kotlin/org/vitrivr/engine/query/operators/transform/filter/FieldLookupLateFilter.kt
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 |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package org.vitrivr.engine.query.operators.transform.filter | ||
|
||
import io.github.oshai.kotlinlogging.KLogger | ||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flow | ||
import kotlinx.coroutines.flow.toList | ||
import org.vitrivr.engine.core.database.descriptor.DescriptorReader | ||
import org.vitrivr.engine.core.model.metamodel.Schema | ||
import org.vitrivr.engine.core.model.query.basics.ComparisonOperator | ||
import org.vitrivr.engine.core.model.retrievable.Retrievable | ||
import org.vitrivr.engine.core.model.retrievable.Retrieved | ||
import org.vitrivr.engine.core.model.retrievable.attributes.PropertyAttribute | ||
import org.vitrivr.engine.core.model.types.Value | ||
import org.vitrivr.engine.core.operators.Operator | ||
import org.vitrivr.engine.core.operators.general.Transformer | ||
import java.sql.Date | ||
import javax.management.Descriptor | ||
|
||
/** | ||
* Appends [Descriptor] to a [Retrieved] based on the values of a [Schema.Field], if available. | ||
* | ||
* @version 1.1.2 | ||
* @author Luca Rossetto | ||
* @author Ralph Gasser | ||
*/ | ||
class FieldLookupLateFilter( | ||
override val input: Operator<out Retrievable>, | ||
/* The reader for a given field. */ | ||
private val reader: DescriptorReader<*>, | ||
/* keys to filter on */ | ||
val keys: List<String>, | ||
/* boolean operator*/ | ||
val comparison: ComparisonOperator = ComparisonOperator.EQ, | ||
/* value to compare to */ | ||
val value: String, | ||
/* append field*/ | ||
val append: Boolean, | ||
/* appends late filter */ | ||
val limit: Int = Int.MAX_VALUE, | ||
override val name: String | ||
) : Transformer { | ||
private val logger: KLogger = KotlinLogging.logger {} | ||
|
||
override fun toFlow(scope: CoroutineScope): Flow<Retrievable> = flow { | ||
/* Parse input IDs.*/ | ||
val inputRetrieved = input.toFlow(scope).toList() | ||
|
||
/* Fetch entries for the provided IDs. */ | ||
val ids = inputRetrieved.map { it.id }.toSet() | ||
val descriptors = if (ids.isEmpty()) { | ||
emptyMap() | ||
} else { | ||
this@FieldLookupLateFilter.reader.getAllForRetrievable(ids).associateBy { it.retrievableId!! } | ||
} | ||
|
||
// Multi keys for | ||
if (keys.size > 1) | ||
throw IllegalArgumentException("only one key is supported yet") | ||
|
||
var emitted = 0 | ||
/* Emit retrievable with added attribute. */ | ||
inputRetrieved.forEach { retrieved -> | ||
val descriptor = descriptors[retrieved.id] | ||
if (descriptor != null) { | ||
//retrieved.addDescriptor(descriptor) | ||
/* Somewhat experimental. Goal: Attach information in a meaningful manner, such that it can be serialised */ | ||
val values = descriptor.values().toMap() | ||
val attribute = keys.map { | ||
(when (values[it]) { | ||
is Value.String -> Pair(it to (values[it] as Value.String), Value.of(value.toString())) | ||
is Value.Text -> Pair(it to (values[it] as Value.Text), Value.of(value.toString())) | ||
is Value.Boolean -> Pair(it to (values[it] as Value.Boolean), Value.of(value.toBoolean())) | ||
is Value.Int -> Pair(it to (values[it] as Value.Int), Value.of(value.toInt())) | ||
is Value.Long -> Pair(it to (values[it] as Value.Long), Value.of(value.toLong())) | ||
is Value.Float -> Pair(it to (values[it] as Value.Float), Value.of(value.toFloat())) | ||
is Value.Double -> Pair(it to (values[it] as Value.Double), Value.of(value.toDouble())) | ||
is Value.Byte -> Pair(it to (values[it] as Value.Byte), Value.of(value.toByte())) | ||
is Value.Short -> Pair(it to (values[it] as Value.Short), Value.of(value.toShort())) | ||
is Value.DateTime -> Pair(it to (values[it] as Value.DateTime), Value.of(Date.valueOf(value))) | ||
else -> Pair(it to null, null) | ||
}) | ||
} | ||
|
||
retrieved.takeIf { append == true }?.let { | ||
retrieved.addDescriptor(descriptor) | ||
retrieved.addAttribute(PropertyAttribute(attribute.map { it.first.first.toString() to it.first.second!!.value.toString() } | ||
.toMap())) | ||
} | ||
|
||
attribute[0].takeIf { it.first.second != null && it.second != null }?.let { | ||
it.takeIf { ++emitted <= limit && comparison.compare(it.first.second!!, it.second!!) }?.let { | ||
emit(retrieved) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is wrong with
Distance.fromString(value.toUpper())
?