Skip to content

Commit 52584a8

Browse files
authored
fix(workflow-operator): qualify the AsterixDB FROM clause; add AsterixDBSourceOpExec unit tests (apache#6878)
### What changes were proposed in this PR? **Source fix.** `AsterixDBSourceOpExec.addBaseSelect` built its query with ```scala s"... FROM $desc.database.$desc.table WHERE 1 = 1 " ``` In Scala that interpolates the `desc` **object** and then appends the literal text `.database` / `.table`, so the generated FROM clause was malformed and the operator's main query could never run. Line 288 of the same file already does it correctly (`desc.database + "." + desc.table`), confirming the intent. Fixed to `${desc.database}.${desc.table}`. The bug surfaced while writing tests for this file, which had **0% coverage**. A reviewer rightly pointed out the first draft pinned the buggy string; the spec now asserts the corrected clause instead. **Tests.** Adds `AsterixDBSourceOpExecSpec` (47 tests) covering the SQL++ string-building surface (no JDBC in this class): - `addFilterConditions` and each branch it dispatches to — `addKeywordSearch` (ftcontains; `IllegalArgumentException` on a non-STRING column), `addRegexSearch`, `addGeoSearch` (create_rectangle for 2 corners, create_polygon beyond that, OR-joined spatial_intersect, `NumberFormatException` on a malformed point), `addGeneralFilterCondition`; - the skip paths for every toggle-off / missing-input case, and the composed keyword→regex→geo→general ordering; - schema derivation from the AsterixDB datatype, and the base-select/limit/offset fragments. **Test-infra fix.** `AsterixDBConnUtilSpec` now removes only its own keys from the JVM-wide `AsterixDBConnUtil.asterixDBVersionMapping` singleton instead of calling `clear()`: sbt runs suites in parallel within one JVM, so a blanket clear could evict the new suite's cached entry mid-run. Both suites also now call `super.beforeAll`/`beforeEach` and wrap `afterAll` teardown in try/finally. ### Any related issues, documentation, discussions? Closes apache#6875. ### How was this PR tested? `sbt -java-home <jbr-17> "WorkflowOperator/testOnly *AsterixDB*"` -> 84 succeeded, 0 failed (across `AsterixDBSourceOpExecSpec`, `AsterixDBConnUtilSpec`, `AsterixDBSourceOpDescSpec`). `Test/scalafmtCheck`, `scalafmtCheck`, `Test/scalafix --check` and `scalafix --check` all clean. ### Was this PR authored or co-authored using generative AI tooling? Generated-by: Claude Code (Opus 4.8 [1M context])
1 parent d5b852a commit 52584a8

3 files changed

Lines changed: 752 additions & 8 deletions

File tree

‎common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/source/sql/asterixdb/AsterixDBSourceOpExec.scala‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ class AsterixDBSourceOpExec private[asterixdb] (
308308
.map((entry: (String, Int)) => {
309309
s"if_missing(${entry._1},null) field_${entry._2}"
310310
})
311-
.mkString(", ")} FROM $desc.database.$desc.table WHERE 1 = 1 "
311+
.mkString(", ")} FROM ${desc.database}.${desc.table} WHERE 1 = 1 "
312312
}
313313

314314
override def addLimit(queryBuilder: StringBuilder): Unit = {

‎common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/source/sql/asterixdb/AsterixDBConnUtilSpec.scala‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,28 @@ class AsterixDBConnUtilSpec
113113
private def lastQueryField(name: String): String =
114114
recordedQueries.synchronized { recordedQueries.last(name) }
115115

116-
override protected def beforeAll(): Unit = server.start()
116+
override protected def beforeAll(): Unit = {
117+
super.beforeAll()
118+
server.start()
119+
}
117120

118121
override protected def afterAll(): Unit = {
119-
server.stop(0)
120-
// Don't leak this suite's entries into the shared-JVM singleton.
121-
AsterixDBConnUtil.asterixDBVersionMapping.clear()
122+
try {
123+
server.stop(0)
124+
// Don't leak this suite's entries into the shared-JVM singleton. Only this
125+
// suite's own keys are dropped: sbt runs suites in parallel in one JVM, and
126+
// AsterixDBSourceOpExecSpec relies on its own entry staying put.
127+
AsterixDBConnUtil.asterixDBVersionMapping -= host
128+
AsterixDBConnUtil.asterixDBVersionMapping -= "some-other-host"
129+
} finally super.afterAll()
122130
}
123131

124132
override protected def beforeEach(): Unit = {
125-
// The version cache is a mutable singleton keyed by host; reset it so every
126-
// test starts from a cold cache, along with the stub's canned responses.
127-
AsterixDBConnUtil.asterixDBVersionMapping.clear()
133+
super.beforeEach()
134+
// The version cache is a mutable singleton keyed by host; reset this suite's
135+
// key so every test starts from a cold cache, along with the stub's canned
136+
// responses.
137+
AsterixDBConnUtil.asterixDBVersionMapping -= host
128138
versionHits.set(0)
129139
versionStatus = 200
130140
versionBody = versionJson("0.9.9")

0 commit comments

Comments
 (0)