Skip to content

Commit 42d0ee7

Browse files
Implement Fetch query (#796)
## What is the goal of this PR? We update to the newest version of TypeDB Driver which supports Fetch queries. As Fetch queries return a stream of JSONs, they are only available in text output view, not as a graph. For more details, see typedb/typeql#300 ## What are the changes implemented in this PR? Closes typedb/typedb#6921
1 parent 09aa8a2 commit 42d0ee7

22 files changed

+166
-124
lines changed

WORKSPACE

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,17 @@ unuseddeps_deps()
103103
load("@vaticle_dependencies//tool/common:deps.bzl", "vaticle_dependencies_ci_pip",
104104
vaticle_dependencies_tool_maven_artifacts = "maven_artifacts")
105105

106+
# Load //tool/docs
107+
load("@vaticle_dependencies//tool/docs:python_deps.bzl", docs_deps = "deps")
108+
docs_deps()
109+
load("@vaticle_dependencies_tool_docs//:requirements.bzl", install_doc_deps = "install_deps")
110+
install_doc_deps()
111+
112+
load("@vaticle_dependencies//tool/docs:java_deps.bzl", java_doc_deps = "deps")
113+
java_doc_deps()
114+
load("@google_bazel_common//:workspace_defs.bzl", "google_common_workspace_rules")
115+
google_common_workspace_rules()
116+
106117
#####################################################################
107118
# Load @vaticle_bazel_distribution from (@vaticle_dependencies) #
108119
#####################################################################

dependencies/maven/artifacts.snapshot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
@maven//:org_jetbrains_skiko_skiko_awt_runtime_macos_arm64_0_7_34
138138
@maven//:org_jetbrains_skiko_skiko_awt_runtime_macos_x64_0_7_34
139139
@maven//:org_jetbrains_skiko_skiko_awt_runtime_windows_x64_0_7_34
140+
@maven//:org_jsoup_jsoup_1_16_1
140141
@maven//:org_mockito_mockito_core_2_6_4
141142
@maven//:org_objenesis_objenesis_2_5
142143
@maven//:org_slf4j_jcl_over_slf4j_2_0_0

dependencies/vaticle/artifacts.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ def vaticle_typedb_artifact():
2525
artifact_name = "typedb-server-{platform}-{version}.{ext}",
2626
tag_source = deployment["artifact.release"],
2727
commit_source = deployment["artifact.snapshot"],
28-
commit = "f73907a60494228973cf3372b3eecb91770c90dd",
28+
commit = "525ac0f5e072242c1d2f360379e9622397497ef2",
2929
)

dependencies/vaticle/repositories.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def vaticle_dependencies():
2828
git_repository(
2929
name = "vaticle_dependencies",
3030
remote = "https://github.com/vaticle/dependencies",
31-
commit = "fcc9a56b65e6ab69bbf0f1680affe38e12617ed6", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_dependencies
31+
commit = "adda846178ed799aca001cc9dfd7934cd4f805a8", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_dependencies
3232
)
3333

3434
def vaticle_force_graph():
@@ -48,6 +48,6 @@ def vaticle_typedb_common():
4848
def vaticle_typedb_driver():
4949
git_repository(
5050
name = "vaticle_typedb_driver",
51-
remote = "https://github.com/vaticle/typedb-driver",
52-
tag = "2.24.15", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_client_java
51+
remote = "https://github.com/dmitrii-ubskii/typedb-driver",
52+
tag = "2.25.0", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_client_java
5353
)

framework/graph/GraphBuilder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class GraphBuilder(
171171
private fun renderEdges(type: Type, rendered: MutableMap<Vertex, Set<Pair<String, Vertex.Type>>>): Set<Pair<String, Vertex.Type>> {
172172
if (type.isRoot) return emptySet()
173173

174-
val superType = type.getSupertype(transactionState.transaction)!!
174+
val superType = type.getSupertype(transactionState.transaction).resolve()!!
175175
if (!allTypeVertices.containsKey(type.label.name())) return renderEdges(superType, rendered)
176176

177177
val typeVertex = allTypeVertices[type.label.name()]!!

framework/output/LogOutput.kt

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import androidx.compose.ui.text.SpanStyle
2828
import androidx.compose.ui.unit.dp
2929
import com.vaticle.typedb.driver.api.answer.ConceptMap
3030
import com.vaticle.typedb.driver.api.answer.ConceptMapGroup
31-
import com.vaticle.typedb.driver.api.answer.Numeric
32-
import com.vaticle.typedb.driver.api.answer.NumericGroup
31+
import com.vaticle.typedb.driver.api.answer.JSON
32+
import com.vaticle.typedb.driver.api.answer.ValueGroup
3333
import com.vaticle.typedb.driver.api.concept.Concept
3434
import com.vaticle.typedb.driver.api.concept.thing.Attribute
3535
import com.vaticle.typedb.driver.api.concept.thing.Relation
@@ -144,7 +144,7 @@ internal class LogOutput constructor(
144144

145145
internal fun outputFn(message: Response.Message): () -> Unit = { output(message.type, message.text) }
146146

147-
internal fun outputFn(numeric: Numeric): () -> Unit = { output(TYPEQL, numeric.toString()) }
147+
internal fun outputFn(value: Value?): () -> Unit = { output(TYPEQL, printValue(value)) }
148148

149149
internal fun outputFn(conceptMap: ConceptMap): () -> Unit {
150150
val output = loadToString(conceptMap)
@@ -156,8 +156,13 @@ internal class LogOutput constructor(
156156
return { output(TYPEQL, output) }
157157
}
158158

159-
internal fun outputFn(numericGroup: NumericGroup): () -> Unit {
160-
val output = loadToString(numericGroup)
159+
internal fun outputFn(valueGroup: ValueGroup): () -> Unit {
160+
val output = loadToString(valueGroup)
161+
return { output(TYPEQL, output) }
162+
}
163+
164+
internal fun outputFn(json: JSON): () -> Unit {
165+
val output = loadToString(json)
161166
return { output(TYPEQL, output) }
162167
}
163168

@@ -185,10 +190,12 @@ internal class LogOutput constructor(
185190
return builder.toAnnotatedString()
186191
}
187192

188-
private fun loadToString(group: NumericGroup): String {
189-
return loadToString(group.owner()) + " => " + group.numeric().asNumber()
193+
private fun loadToString(group: ValueGroup): String {
194+
return loadToString(group.owner()) + " => " + group.value().toString()
190195
}
191196

197+
private fun loadToString(json: JSON): String = json.toString()
198+
192199
private fun loadToString(group: ConceptMapGroup): String {
193200
val str = StringBuilder(loadToString(group.owner()) + " => {\n")
194201
group.conceptMaps().forEach { str.append(Strings.indent(loadToString(it))) }
@@ -230,7 +237,7 @@ internal class LogOutput constructor(
230237
private fun printType(type: Type): String {
231238
var str = TypeQLToken.Constraint.TYPE.toString() + " " + type.label
232239
transactionState.transaction?.let {
233-
type.getSupertype(it)?.let {
240+
type.getSupertype(it).resolve()?.let {
234241
str += " " + TypeQLToken.Constraint.SUB + " " + it.label.scopedName()
235242
}
236243
}
@@ -258,7 +265,7 @@ internal class LogOutput constructor(
258265
return "($rolePlayers)"
259266
}
260267

261-
private fun printValue(value: Value) = Strings.valueToString(value)
268+
private fun printValue(value: Value?) = value?.let { Strings.valueToString(value) } ?: "NaN"
262269

263270
@OptIn(ExperimentalComposeUiApi::class)
264271
@Composable

framework/output/RunOutputGroup.kt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import com.vaticle.typedb.studio.service.common.StatusService.Key.OUTPUT_RESPONS
3232
import com.vaticle.typedb.studio.service.common.StatusService.Key.QUERY_RESPONSE_TIME
3333
import com.vaticle.typedb.studio.service.connection.QueryRunner
3434
import com.vaticle.typedb.studio.service.connection.QueryRunner.Response
35-
import com.vaticle.typedb.studio.service.connection.QueryRunner.Response.Stream.ConceptMaps.Source.MATCH
35+
import com.vaticle.typedb.studio.service.connection.QueryRunner.Response.Stream.ConceptMaps.Source.GET
3636
import java.util.concurrent.CompletableFuture
3737
import java.util.concurrent.CountDownLatch
3838
import java.util.concurrent.LinkedBlockingQueue
@@ -164,20 +164,21 @@ internal class RunOutputGroup constructor(
164164

165165
private suspend fun consumeResponse(response: Response) = when (response) {
166166
is Response.Message -> consumeMessageResponse(response)
167-
is Response.Numeric -> consumeNumericResponse(response)
167+
is Response.Value -> consumeValueResponse(response)
168168
is Response.Stream<*> -> when (response) {
169-
is Response.Stream.NumericGroups -> consumeNumericGroupStreamResponse(response)
169+
is Response.Stream.ValueGroups -> consumeValueGroupStreamResponse(response)
170170
is Response.Stream.ConceptMapGroups -> consumeConceptMapGroupStreamResponse(response)
171171
is Response.Stream.ConceptMaps -> consumeConceptMapStreamResponse(response)
172+
is Response.Stream.JSONs -> consumeJSONStreamResponse(response)
172173
}
173174
is Response.Done -> {}
174175
}
175176

176177
private fun consumeMessageResponse(response: Response.Message) = collectSerial(logOutput.outputFn(response))
177178

178-
private fun consumeNumericResponse(response: Response.Numeric) = collectSerial(logOutput.outputFn(response.value))
179+
private fun consumeValueResponse(response: Response.Value) = collectSerial(logOutput.outputFn(response.value))
179180

180-
private suspend fun consumeNumericGroupStreamResponse(response: Response.Stream.NumericGroups) {
181+
private suspend fun consumeValueGroupStreamResponse(response: Response.Stream.ValueGroups) {
181182
consumeStreamResponse(response) {
182183
collectSerial(
183184
launchCompletableFuture(
@@ -196,11 +197,11 @@ internal class RunOutputGroup constructor(
196197
private suspend fun consumeConceptMapStreamResponse(response: Response.Stream.ConceptMaps) {
197198
val notificationSrv = Service.notification
198199
// TODO: enable configuration of displaying GraphOutput for INSERT and UPDATE
199-
val table = if (response.source != MATCH) null else TableOutput(
200+
val table = if (response.source != GET) null else TableOutput(
200201
transaction = runner.transactionState, number = tableCount.incrementAndGet()
201202
) // TODO: .also { outputs.add(it) }
202203
val graph =
203-
if (response.source != MATCH || !Service.preference.graphOutputEnabled) null else GraphOutput(
204+
if (response.source != GET || !Service.preference.graphOutputEnabled) null else GraphOutput(
204205
transactionState = runner.transactionState, number = graphCount.incrementAndGet()
205206
).also { outputs.add(it); activate(it) }
206207

@@ -211,6 +212,10 @@ internal class RunOutputGroup constructor(
211212
}
212213
}
213214

215+
private suspend fun consumeJSONStreamResponse(response: Response.Stream.JSONs) = consumeStreamResponse(response) {
216+
collectSerial(launchCompletableFuture(Service.notification, LOGGER) { logOutput.outputFn(it) })
217+
}
218+
214219
private suspend fun <T> consumeStreamResponse(
215220
stream: Response.Stream<T>,
216221
consumer: (T) -> Unit

module/preference/PreferenceDialog.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,8 @@ object PreferenceDialog {
429429
private const val TRANSACTION_TIMEOUT_MINS_PLACEHOLDER = "5"
430430
}
431431

432-
private var matchQueryLimit = PreferenceField.TextInputValidated(
433-
initValue = preferenceSrv.matchQueryLimit.toString(),
432+
private var getQueryLimit = PreferenceField.TextInputValidated(
433+
initValue = preferenceSrv.getQueryLimit.toString(),
434434
label = SET_QUERY_LIMIT, placeholder = QUERY_LIMIT_PLACEHOLDER,
435435
invalidWarning = Label.PREFERENCE_INTEGER_WARNING, caption = PREFERENCES_MATCH_QUERY_LIMIT_CAPTION
436436
) {/* validator = */ it.toLongOrNull() != null && it.toLongOrNull()!! >= 0 }
@@ -445,19 +445,19 @@ object PreferenceDialog {
445445
transactionTimeoutMins in 1..10000
446446
}
447447

448-
override val preferences: List<PreferenceField> = listOf(matchQueryLimit, transactionTimeoutMins)
448+
override val preferences: List<PreferenceField> = listOf(getQueryLimit, transactionTimeoutMins)
449449

450450
override fun submit() {
451-
preferenceSrv.matchQueryLimit = matchQueryLimit.value.toLong()
451+
preferenceSrv.getQueryLimit = getQueryLimit.value.toLong()
452452
preferenceSrv.transactionTimeoutMins = transactionTimeoutMins.value.toLong()
453-
matchQueryLimit.modified = false
453+
getQueryLimit.modified = false
454454
transactionTimeoutMins.modified = false
455455
}
456456

457457
override fun reset() {
458-
matchQueryLimit.value = preferenceSrv.matchQueryLimit.toString()
458+
getQueryLimit.value = preferenceSrv.getQueryLimit.toString()
459459
transactionTimeoutMins.value = preferenceSrv.transactionTimeoutMins.toString()
460-
matchQueryLimit.modified = false
460+
getQueryLimit.modified = false
461461
transactionTimeoutMins.modified = false
462462
}
463463
}
@@ -566,4 +566,4 @@ object PreferenceDialog {
566566
Separator.Horizontal()
567567
ColumnSpacer()
568568
}
569-
}
569+
}

service/common/DataService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class DataService {
113113
get() = properties?.getProperty(IGNORED_PATHS)?.split(',')?.map { it.trim() }
114114
set(value) = setProperty(IGNORED_PATHS, value!!.joinToString(","))
115115

116-
var matchQueryLimit: Long?
116+
var getQueryLimit: Long?
117117
get() = properties?.getProperty(MATCH_QUERY_LIMIT)?.toLong()
118118
set(value) = setProperty(MATCH_QUERY_LIMIT, value!!.toString())
119119

service/common/PreferenceService.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ class PreferenceService(dataSrv: DataService) {
3535
get() = preferences.graphOutputEnabled ?: field
3636
set(value) = run { preferences.graphOutputEnabled = value }
3737

38-
var matchQueryLimit: Long = Defaults.matchQueryLimit
39-
get() = preferences.matchQueryLimit ?: field
40-
set(value) = run { preferences.matchQueryLimit = value }
38+
var getQueryLimit: Long = Defaults.getQueryLimit
39+
get() = preferences.getQueryLimit ?: field
40+
set(value) = run { preferences.getQueryLimit = value }
4141

4242
var transactionTimeoutMins: Long = Defaults.transactionTimeoutMins
4343
get() = preferences.transactionTimeoutMins ?: field
@@ -60,8 +60,8 @@ class PreferenceService(dataSrv: DataService) {
6060
private object Defaults {
6161
val autoSave = true
6262
val graphOutputEnabled = true
63-
val matchQueryLimit = 1000L
63+
val getQueryLimit = 1000L
6464
val ignoredPaths = listOf(".git")
6565
val transactionTimeoutMins = 60L
6666
}
67-
}
67+
}

0 commit comments

Comments
 (0)