|
19 | 19 |
|
20 | 20 | package org.apache.texera.amber.operator.metadata |
21 | 21 |
|
| 22 | +import com.fasterxml.jackson.databind.node.BooleanNode |
22 | 23 | import org.apache.texera.amber.core.state.StateReferencing |
23 | 24 | import org.apache.texera.amber.operator.LogicalOp |
| 25 | +import org.apache.texera.amber.operator.dictionary.DictionaryMatcherOpDesc |
24 | 26 | import org.apache.texera.amber.operator.filter.SpecializedFilterOpDesc |
| 27 | +import org.apache.texera.amber.operator.limit.LimitOpDesc |
| 28 | +import org.apache.texera.amber.operator.projection.ProjectionOpDesc |
| 29 | +import org.apache.texera.amber.operator.sortPartitions.SortPartitionsOpDesc |
| 30 | +import org.apache.texera.amber.operator.source.scan.file.FileScanOpDesc |
| 31 | +import org.apache.texera.amber.operator.unneststring.UnnestStringOpDesc |
25 | 32 | import org.scalatest.flatspec.AnyFlatSpec |
26 | 33 | import org.scalatest.matchers.should.Matchers |
27 | 34 |
|
@@ -52,4 +59,53 @@ class OperatorMetadataGeneratorSpec extends AnyFlatSpec with Matchers { |
52 | 59 | val required = schema.get("required").elements().asScala.map(_.asText()).toList |
53 | 60 | required should not contain StateReferencing.SIDECAR_PROPERTY |
54 | 61 | } |
| 62 | + |
| 63 | + /** The properties of `opDescClass`'s schema whose `noLoopVariable` keyword is `true`. */ |
| 64 | + private def markedNoLoopVariable(opDescClass: Class[_ <: LogicalOp]): Set[String] = |
| 65 | + OperatorMetadataGenerator |
| 66 | + .generateOperatorJsonSchema(opDescClass) |
| 67 | + .get("properties") |
| 68 | + .fields() |
| 69 | + .asScala |
| 70 | + .filter(_.getValue.get("noLoopVariable") == BooleanNode.TRUE) |
| 71 | + .map(_.getKey) |
| 72 | + .toSet |
| 73 | + |
| 74 | + it should "mark each property that cannot hold a loop variable with 'noLoopVariable', by its JSON name" in { |
| 75 | + markedNoLoopVariable(classOf[ProjectionOpDesc]) shouldBe Set("isDrop", "attributes") |
| 76 | + // Renamed in JSON: the panel looks the property up by the name the schema gives it. |
| 77 | + markedNoLoopVariable(classOf[DictionaryMatcherOpDesc]) shouldBe Set("result attribute") |
| 78 | + markedNoLoopVariable(classOf[UnnestStringOpDesc]) shouldBe Set("Result attribute") |
| 79 | + // `attributeName` is declared and marked by the TextSourceOpDesc trait. |
| 80 | + markedNoLoopVariable(classOf[FileScanOpDesc]) shouldBe Set("attributeName", "outputFileName") |
| 81 | + markedNoLoopVariable(classOf[SortPartitionsOpDesc]) shouldBe |
| 82 | + Set("sortAttributeName", "domainMin", "domainMax") |
| 83 | + } |
| 84 | + |
| 85 | + it should "leave 'noLoopVariable' off a property the executor reads after the loop state wrote it" in { |
| 86 | + val properties = Seq( |
| 87 | + classOf[SpecializedFilterOpDesc] -> "predicates", |
| 88 | + classOf[LimitOpDesc] -> "limit", |
| 89 | + classOf[DictionaryMatcherOpDesc] -> "Dictionary", |
| 90 | + classOf[UnnestStringOpDesc] -> "Delimiter" |
| 91 | + ) |
| 92 | + properties.foreach { |
| 93 | + case (opDescClass, name) => |
| 94 | + val schema = OperatorMetadataGenerator.generateOperatorJsonSchema(opDescClass) |
| 95 | + withClue(s"${opDescClass.getSimpleName}.$name: ") { |
| 96 | + schema.get("properties").has(name) shouldBe true |
| 97 | + schema.get("properties").get(name).has("noLoopVariable") shouldBe false |
| 98 | + } |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + it should "generate every operator's schema, marking exactly the properties the compiler rejects a loop variable in" in { |
| 103 | + // One list behind both: what the schema marks is exactly what the compiler checks. |
| 104 | + OperatorMetadataGenerator.operatorTypeMap.keys.foreach { opDescClass => |
| 105 | + withClue(s"${opDescClass.getSimpleName}: ") { |
| 106 | + markedNoLoopVariable(opDescClass) shouldBe |
| 107 | + StateReferencing.noLoopVariableProperties(opDescClass) |
| 108 | + } |
| 109 | + } |
| 110 | + } |
55 | 111 | } |
0 commit comments