-
Notifications
You must be signed in to change notification settings - Fork 140
test(workflow-core): add unit test coverage for ResultSchema #4786
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
Closed
aglinxinyuan
wants to merge
4
commits into
apache:main
from
aglinxinyuan:xinyuan-test-result-schema-spec
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
43c04b4
test(workflow-core): add unit test coverage for ResultSchema
aglinxinyuan 0ef3e85
test(workflow-core): pin every runtime-statistics column type
aglinxinyuan 52176cf
test(workflow-core): tighten ResultSchema test descriptions
aglinxinyuan 743cfb5
test(workflow-core): expand ResultSchemaSpec beyond redeclaration
aglinxinyuan 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
140 changes: 140 additions & 0 deletions
140
...ow-core/src/test/scala/org/apache/texera/amber/core/storage/result/ResultSchemaSpec.scala
This file contains hidden or 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,140 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.texera.amber.core.storage.result | ||
|
|
||
| import org.apache.texera.amber.core.tuple.{AttributeType, Schema} | ||
| import org.scalatest.flatspec.AnyFlatSpec | ||
|
|
||
| class ResultSchemaSpec extends AnyFlatSpec { | ||
|
|
||
| // The expected (name, type) layout of runtimeStatisticsSchema, in the order | ||
| // production code declares it. Multiple tests below depend on this list, so | ||
| // it lives here as a single source of truth for the spec. | ||
| private val runtimeStatsLayout: List[(String, AttributeType)] = List( | ||
| "operatorId" -> AttributeType.STRING, | ||
| "time" -> AttributeType.TIMESTAMP, | ||
| "inputTupleCnt" -> AttributeType.LONG, | ||
| "inputTupleSize" -> AttributeType.LONG, | ||
| "outputTupleCnt" -> AttributeType.LONG, | ||
| "outputTupleSize" -> AttributeType.LONG, | ||
| "dataProcessingTime" -> AttributeType.LONG, | ||
| "controlProcessingTime" -> AttributeType.LONG, | ||
| "idleTime" -> AttributeType.LONG, | ||
| "numWorkers" -> AttributeType.INTEGER, | ||
| "status" -> AttributeType.INTEGER | ||
| ) | ||
|
|
||
| "ResultSchema.runtimeStatisticsSchema" should "list its columns in the declared order" in { | ||
| val actualNames = | ||
| ResultSchema.runtimeStatisticsSchema.getAttributes.map(_.getName) | ||
| assert(actualNames == runtimeStatsLayout.map(_._1)) | ||
| } | ||
|
|
||
| it should "pin every runtime-statistics column to its expected type" in { | ||
| val schema = ResultSchema.runtimeStatisticsSchema | ||
| // Downstream readers deserialize positionally and cast each slot, so each | ||
| // column type matters. Pin all of them, not just a sample. | ||
| runtimeStatsLayout.foreach { | ||
| case (name, expectedType) => | ||
| assert( | ||
| schema.getAttribute(name).getType == expectedType, | ||
| s"$name expected $expectedType, got ${schema.getAttribute(name).getType}" | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| it should "expose a stable name → index mapping for positional readers" in { | ||
| val schema = ResultSchema.runtimeStatisticsSchema | ||
| runtimeStatsLayout.zipWithIndex.foreach { | ||
| case ((name, _), expectedIndex) => | ||
| assert( | ||
| schema.getIndex(name) == expectedIndex, | ||
| s"$name expected index $expectedIndex, got ${schema.getIndex(name)}" | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| it should "throw on lookup of an unknown attribute name" in { | ||
| val schema = ResultSchema.runtimeStatisticsSchema | ||
| val ex = intercept[RuntimeException] { | ||
| schema.getAttribute("not-a-runtime-stats-column") | ||
| } | ||
| assert(ex.getMessage.contains("not-a-runtime-stats-column")) | ||
| assert(!schema.containsAttribute("not-a-runtime-stats-column")) | ||
| } | ||
|
|
||
| it should "have unique column names" in { | ||
| val names = ResultSchema.runtimeStatisticsSchema.getAttributes.map(_.getName) | ||
| assert(names.distinct == names, s"duplicate column names: $names") | ||
| } | ||
|
|
||
| it should "round-trip via toRawSchema → fromRawSchema with stable names and types" in { | ||
| // The cross-language serialization contract that downstream Python / | ||
| // external consumers actually depend on. If a column type drifts so | ||
| // its `AttributeType.name()` no longer round-trips, this fails. | ||
| val original = ResultSchema.runtimeStatisticsSchema | ||
| val raw = original.toRawSchema | ||
| val restored = Schema.fromRawSchema(raw) | ||
| // Names + types must be preserved by the round-trip; column ORDER is not | ||
| // contractually guaranteed by `toRawSchema`'s `Map` return type, so we | ||
| // compare via the (name, type) set instead of full equality. | ||
| assert( | ||
| restored.getAttributes.map(a => a.getName -> a.getType).toSet == | ||
| original.getAttributes.map(a => a.getName -> a.getType).toSet | ||
| ) | ||
| assert(raw.keySet == runtimeStatsLayout.map(_._1).toSet) | ||
| assert(raw == runtimeStatsLayout.map { case (n, t) => n -> t.name() }.toMap) | ||
| } | ||
|
|
||
| it should "be a singleton val (same instance per access)" in { | ||
| // Pin the assumption that consumers can hold references without paying | ||
| // for repeated rebuilds, and that two reads produce structurally-equal | ||
| // schemas at minimum. | ||
| assert(ResultSchema.runtimeStatisticsSchema eq ResultSchema.runtimeStatisticsSchema) | ||
| } | ||
|
|
||
| "ResultSchema.consoleMessagesSchema" should "have a single STRING `message` column" in { | ||
| val schema = ResultSchema.consoleMessagesSchema | ||
| val attrs = schema.getAttributes | ||
| assert(attrs.size == 1) | ||
| assert(attrs.head.getName == "message") | ||
| assert(attrs.head.getType == AttributeType.STRING) | ||
| } | ||
|
|
||
| it should "place `message` at index 0" in { | ||
| assert(ResultSchema.consoleMessagesSchema.getIndex("message") == 0) | ||
| } | ||
|
|
||
| it should "throw on lookup of an unknown attribute name" in { | ||
| val ex = intercept[RuntimeException] { | ||
| ResultSchema.consoleMessagesSchema.getAttribute("not-a-console-column") | ||
| } | ||
| assert(ex.getMessage.contains("not-a-console-column")) | ||
| } | ||
|
|
||
| it should "round-trip to a {message: STRING} raw schema" in { | ||
| val raw = ResultSchema.consoleMessagesSchema.toRawSchema | ||
| assert(raw == Map("message" -> AttributeType.STRING.name())) | ||
| } | ||
|
|
||
| it should "be a singleton val (same instance per access)" in { | ||
| assert(ResultSchema.consoleMessagesSchema eq ResultSchema.consoleMessagesSchema) | ||
| } | ||
| } | ||
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.
do you think this file needs test? seems it only defined three static schemas. Can we skip it?
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.
let's check the coverage about this change. I kind of don't believe the current numbers shown.
Uh oh!
There was an error while loading. Please reload this page.
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.
Fair concern. The motivation is that downstream readers deserialize this schema positionally and cast each slot to a concrete type, so a silent reorder/retype would break consumers without any local-file change being obvious in review (the OG Copilot thread above made the same point). Pinning the column list + types here lets a CI red flag catch the drift instead of waiting for a runtime cast failure.
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.
Expanded the spec in 743cfb5 so it goes beyond redeclaring the schema. New runtimeStatisticsSchema coverage: stable name → index mapping for positional readers; unknown-name lookup throws and the error message names the missing column;
containsAttributereturns false for unknown names; column names are unique;toRawSchema→fromRawSchemaround-trips names + types intact (the cross-language serialization contract that Python and external consumers actually depend on); singleton-val identity. Parallel coverage added forconsoleMessagesSchema. 12 tests total, all passing.Let me know if this changes your mind on closing — happy to either keep it or close if it still feels like ceremony.