aglinxinyuan commented on code in PR #6001:
URL: https://github.com/apache/texera/pull/6001#discussion_r3488694782


##########
common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/projection/AttributeUnitSpec.scala:
##########
@@ -0,0 +1,54 @@
+/*
+ * 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.operator.projection
+
+import org.apache.texera.amber.util.JSONUtils.objectMapper
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+
+class AttributeUnitSpec extends AnyFlatSpec with Matchers {
+
+  "AttributeUnit.getAlias" should "return the alias when one is provided" in {
+    new AttributeUnit("col", "renamed").getAlias shouldBe "renamed"
+    new AttributeUnit("col", "renamed").getOriginalAttribute shouldBe "col"
+  }
+
+  it should "fall back to the original attribute when the alias is blank" in {
+    new AttributeUnit("col", "").getAlias shouldBe "col"
+    new AttributeUnit("col", "   ").getAlias shouldBe "col"
+    new AttributeUnit("col", null).getAlias shouldBe "col"
+  }
+
+  "AttributeUnit" should "honor equals/hashCode by original attribute and 
alias" in {
+    val a = new AttributeUnit("col", "x")
+    val b = new AttributeUnit("col", "x")
+    a shouldBe b
+    a.hashCode shouldBe b.hashCode
+    a should not be new AttributeUnit("col", "y")
+  }
+
+  "AttributeUnit" should "round-trip through Jackson" in {
+    val u = new AttributeUnit("col", "renamed")
+    val json = objectMapper.writeValueAsString(u)
+    json should include("\"originalAttribute\":\"col\"")
+    json should include("\"alias\":\"renamed\"")
+    objectMapper.readValue(json, classOf[AttributeUnit]) shouldBe u

Review Comment:
   Done — now asserts `originalAttribute`/`alias` via a parsed JsonNode.



##########
common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/projection/AttributeUnitSpec.scala:
##########
@@ -0,0 +1,54 @@
+/*
+ * 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.operator.projection
+
+import org.apache.texera.amber.util.JSONUtils.objectMapper
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+
+class AttributeUnitSpec extends AnyFlatSpec with Matchers {
+
+  "AttributeUnit.getAlias" should "return the alias when one is provided" in {
+    new AttributeUnit("col", "renamed").getAlias shouldBe "renamed"
+    new AttributeUnit("col", "renamed").getOriginalAttribute shouldBe "col"
+  }
+
+  it should "fall back to the original attribute when the alias is blank" in {
+    new AttributeUnit("col", "").getAlias shouldBe "col"
+    new AttributeUnit("col", "   ").getAlias shouldBe "col"
+    new AttributeUnit("col", null).getAlias shouldBe "col"
+  }
+
+  "AttributeUnit" should "honor equals/hashCode by original attribute and 
alias" in {
+    val a = new AttributeUnit("col", "x")
+    val b = new AttributeUnit("col", "x")
+    a shouldBe b
+    a.hashCode shouldBe b.hashCode
+    a should not be new AttributeUnit("col", "y")
+  }

Review Comment:
   Good catch — added a not-equal case that varies `originalAttribute` 
(alongside the alias case).



##########
common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/udf/python/LambdaAttributeUnitSpec.scala:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.operator.udf.python
+
+import org.apache.texera.amber.core.tuple.AttributeType
+import org.apache.texera.amber.util.JSONUtils.objectMapper
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+
+class LambdaAttributeUnitSpec extends AnyFlatSpec with Matchers {
+
+  "LambdaAttributeUnit" should "expose its constructor-supplied fields" in {
+    val u = new LambdaAttributeUnit("score", "1 + 1", "scoreOut", 
AttributeType.INTEGER)
+    u.attributeName shouldBe "score"
+    u.expression shouldBe "1 + 1"
+    u.newAttributeName shouldBe "scoreOut"
+    u.attributeType shouldBe AttributeType.INTEGER
+  }
+
+  "LambdaAttributeUnit" should "honor equals/hashCode by all four fields" in {
+    val a = new LambdaAttributeUnit("score", "1 + 1", "scoreOut", 
AttributeType.INTEGER)
+    val b = new LambdaAttributeUnit("score", "1 + 1", "scoreOut", 
AttributeType.INTEGER)
+    a shouldBe b
+    a.hashCode shouldBe b.hashCode
+    a should not be new LambdaAttributeUnit("score", "1 + 2", "scoreOut", 
AttributeType.INTEGER)
+  }
+
+  "LambdaAttributeUnit" should "round-trip through Jackson" in {
+    val u = new LambdaAttributeUnit("score", "1 + 1", "scoreOut", 
AttributeType.INTEGER)
+    val json = objectMapper.writeValueAsString(u)
+    json should include("\"attributeName\":\"score\"")
+    json should include("\"expression\":\"1 + 1\"")
+    objectMapper.readValue(json, classOf[LambdaAttributeUnit]) shouldBe u

Review Comment:
   Done — asserts the four fields via a parsed JsonNode now.



##########
common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/udf/python/LambdaAttributeUnitSpec.scala:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.operator.udf.python
+
+import org.apache.texera.amber.core.tuple.AttributeType
+import org.apache.texera.amber.util.JSONUtils.objectMapper
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+
+class LambdaAttributeUnitSpec extends AnyFlatSpec with Matchers {
+
+  "LambdaAttributeUnit" should "expose its constructor-supplied fields" in {
+    val u = new LambdaAttributeUnit("score", "1 + 1", "scoreOut", 
AttributeType.INTEGER)
+    u.attributeName shouldBe "score"
+    u.expression shouldBe "1 + 1"
+    u.newAttributeName shouldBe "scoreOut"
+    u.attributeType shouldBe AttributeType.INTEGER
+  }
+
+  "LambdaAttributeUnit" should "honor equals/hashCode by all four fields" in {
+    val a = new LambdaAttributeUnit("score", "1 + 1", "scoreOut", 
AttributeType.INTEGER)
+    val b = new LambdaAttributeUnit("score", "1 + 1", "scoreOut", 
AttributeType.INTEGER)
+    a shouldBe b
+    a.hashCode shouldBe b.hashCode
+    a should not be new LambdaAttributeUnit("score", "1 + 2", "scoreOut", 
AttributeType.INTEGER)

Review Comment:
   Done — added not-equal cases varying `newAttributeName` and `attributeType` 
(plus `attributeName` and `expression`), so all four fields are pinned.



##########
common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/typecasting/TypeCastingUnitSpec.scala:
##########
@@ -0,0 +1,47 @@
+/*
+ * 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.operator.typecasting
+
+import org.apache.texera.amber.core.tuple.AttributeType
+import org.apache.texera.amber.util.JSONUtils.objectMapper
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+
+class TypeCastingUnitSpec extends AnyFlatSpec with Matchers {
+
+  "TypeCastingUnit" should "expose its attribute and result-type fields" in {
+    val u = new TypeCastingUnit
+    u.attribute = "amount"
+    u.resultType = AttributeType.DOUBLE
+    u.attribute shouldBe "amount"
+    u.resultType shouldBe AttributeType.DOUBLE
+  }
+
+  "TypeCastingUnit" should "round-trip its fields through Jackson" in {
+    val u = new TypeCastingUnit
+    u.attribute = "amount"
+    u.resultType = AttributeType.INTEGER
+    val json = objectMapper.writeValueAsString(u)
+    json should include("\"attribute\":\"amount\"")
+    val restored = objectMapper.readValue(json, classOf[TypeCastingUnit])
+    restored.attribute shouldBe "amount"
+    restored.resultType shouldBe AttributeType.INTEGER

Review Comment:
   Done — asserts `attribute`/`resultType`("integer") via a parsed JsonNode now.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to