Copilot commented on code in PR #4369: URL: https://github.com/apache/texera/pull/4369#discussion_r3070389216
########## common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/source/scan/file/InputFileScanSourceOpDesc.scala: ########## @@ -0,0 +1,101 @@ +/* + * 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.source.scan.file + +import com.fasterxml.jackson.annotation.JsonProperty +import com.kjetland.jackson.jsonSchema.annotations.{ + JsonSchemaInject, + JsonSchemaString, + JsonSchemaTitle +} +import org.apache.texera.amber.core.executor.OpExecWithClassName +import org.apache.texera.amber.core.tuple.{AttributeType, Schema} +import org.apache.texera.amber.core.virtualidentity.{ExecutionIdentity, WorkflowIdentity} +import org.apache.texera.amber.core.workflow.{ + InputPort, + OutputPort, + PhysicalOp, + SchemaPropagationFunc +} +import org.apache.texera.amber.operator.metadata.annotations.HideAnnotation +import org.apache.texera.amber.operator.metadata.{OperatorGroupConstants, OperatorInfo} +import org.apache.texera.amber.operator.source.SourceOperatorDescriptor +import org.apache.texera.amber.operator.source.scan.FileDecodingMethod +import org.apache.texera.amber.operator.source.scan.text.TextSourceOpDesc +import org.apache.texera.amber.util.JSONUtils.objectMapper + +class InputFileScanSourceOpDesc extends SourceOperatorDescriptor with TextSourceOpDesc { + @JsonProperty(defaultValue = "UTF_8", required = true) + @JsonSchemaTitle("Encoding") + var fileEncoding: FileDecodingMethod = FileDecodingMethod.UTF_8 + + @JsonProperty(defaultValue = "false") + @JsonSchemaTitle("Extract") + val extract: Boolean = false + + @JsonProperty(defaultValue = "false") + @JsonSchemaTitle("Include Filename") + @JsonSchemaInject( + strings = Array( + new JsonSchemaString(path = HideAnnotation.hideTarget, value = "extract"), + new JsonSchemaString(path = HideAnnotation.hideType, value = HideAnnotation.Type.equals), + new JsonSchemaString(path = HideAnnotation.hideExpectedValue, value = "false") + ) + ) + val outputFileName: Boolean = false + + override def getPhysicalOp( + workflowId: WorkflowIdentity, + executionId: ExecutionIdentity + ): PhysicalOp = { + PhysicalOp + .sourcePhysicalOp( + workflowId, + executionId, + operatorIdentifier, + OpExecWithClassName( + "org.apache.texera.amber.operator.source.scan.file.InputFileScanSourceOpExec", + objectMapper.writeValueAsString(this) + ) Review Comment: `getPhysicalOp` uses an `OpExecWithClassName` string that points to `org.apache.texera.amber.operator.source.scan.InputFileScanSourceOpExec`, but the executor added in this PR is in package `org.apache.texera.amber.operator.source.scan.file`. As written, workflow execution will fail at runtime when the engine tries to instantiate the operator executor. Update the fully-qualified class name to the actual executor class’ package/name. ########## common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/source/scan/file/InputFileScanSourceOpDesc.scala: ########## @@ -0,0 +1,101 @@ +/* + * 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.source.scan.file + +import com.fasterxml.jackson.annotation.JsonProperty +import com.kjetland.jackson.jsonSchema.annotations.{ + JsonSchemaInject, + JsonSchemaString, + JsonSchemaTitle +} +import org.apache.texera.amber.core.executor.OpExecWithClassName +import org.apache.texera.amber.core.tuple.{AttributeType, Schema} +import org.apache.texera.amber.core.virtualidentity.{ExecutionIdentity, WorkflowIdentity} +import org.apache.texera.amber.core.workflow.{ + InputPort, + OutputPort, + PhysicalOp, + SchemaPropagationFunc +} +import org.apache.texera.amber.operator.metadata.annotations.HideAnnotation +import org.apache.texera.amber.operator.metadata.{OperatorGroupConstants, OperatorInfo} +import org.apache.texera.amber.operator.source.SourceOperatorDescriptor +import org.apache.texera.amber.operator.source.scan.FileDecodingMethod +import org.apache.texera.amber.operator.source.scan.text.TextSourceOpDesc +import org.apache.texera.amber.util.JSONUtils.objectMapper + +class InputFileScanSourceOpDesc extends SourceOperatorDescriptor with TextSourceOpDesc { + @JsonProperty(defaultValue = "UTF_8", required = true) + @JsonSchemaTitle("Encoding") + var fileEncoding: FileDecodingMethod = FileDecodingMethod.UTF_8 + + @JsonProperty(defaultValue = "false") + @JsonSchemaTitle("Extract") + val extract: Boolean = false + + @JsonProperty(defaultValue = "false") + @JsonSchemaTitle("Include Filename") + @JsonSchemaInject( + strings = Array( + new JsonSchemaString(path = HideAnnotation.hideTarget, value = "extract"), + new JsonSchemaString(path = HideAnnotation.hideType, value = HideAnnotation.Type.equals), + new JsonSchemaString(path = HideAnnotation.hideExpectedValue, value = "false") + ) + ) + val outputFileName: Boolean = false + + override def getPhysicalOp( + workflowId: WorkflowIdentity, + executionId: ExecutionIdentity + ): PhysicalOp = { + PhysicalOp + .sourcePhysicalOp( + workflowId, + executionId, + operatorIdentifier, + OpExecWithClassName( + "org.apache.texera.amber.operator.source.scan.file.InputFileScanSourceOpExec", + objectMapper.writeValueAsString(this) + ) + ) + .withInputPorts(operatorInfo.inputPorts) + .withOutputPorts(operatorInfo.outputPorts) + .withPropagateSchema( + SchemaPropagationFunc(_ => Map(operatorInfo.outputPorts.head.id -> sourceSchema())) + ) + } Review Comment: `getPhysicalOp` builds a `sourcePhysicalOp`, but this operator declares a non-empty `inputPorts` list and its executor consumes upstream tuples. `PhysicalOp.sourcePhysicalOp` is documented/implemented for true sources (no input ports, pinned to controller, 1 worker). Consider using `PhysicalOp.oneToOnePhysicalOp` (or an appropriate non-source physical op factory) so planning/execution semantics match the operator’s actual behavior and avoid unnecessarily forcing controller placement / single-worker execution. ########## common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/source/scan/file/InputFileScanSourceOpExec.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.source.scan.file + +import org.apache.texera.amber.core.executor.OperatorExecutor +import org.apache.texera.amber.core.storage.FileResolver +import org.apache.texera.amber.core.tuple.{Tuple, TupleLike} +import org.apache.texera.amber.util.JSONUtils.objectMapper + +class InputFileScanSourceOpExec private[scan] ( + descString: String +) extends OperatorExecutor { + private val desc: InputFileScanSourceOpDesc = + objectMapper.readValue(descString, classOf[InputFileScanSourceOpDesc]) + + override def processTuple(tuple: Tuple, port: Int): Iterator[TupleLike] = { + val fileName = + FileResolver.resolve(tuple.getFields.collectFirst { case s: String => s }.get).toASCIIString Review Comment: New operator `InputFileScanSourceOpDesc`/`InputFileScanSourceOpExec` introduces new behavior (extracting file paths from upstream tuples and resolving them), but there doesn’t appear to be an accompanying unit test similar to the existing `FileScanSourceOp*Spec`s. Adding a focused test (e.g., with a temp file path tuple, plus a negative case for non-string / missing fields) would help prevent regressions. ```suggestion val inputFilePath = tuple.getFields.collectFirst { case s: String => s }.getOrElse { throw new IllegalArgumentException( s"InputFileScanSourceOpExec requires at least one string field containing a file path, but received tuple fields: ${tuple.getFields.mkString("[", ", ", "]")}" ) } val fileName = FileResolver.resolve(inputFilePath).toASCIIString ``` ########## common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/source/scan/file/InputFileScanSourceOpExec.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.source.scan.file + +import org.apache.texera.amber.core.executor.OperatorExecutor +import org.apache.texera.amber.core.storage.FileResolver +import org.apache.texera.amber.core.tuple.{Tuple, TupleLike} +import org.apache.texera.amber.util.JSONUtils.objectMapper + +class InputFileScanSourceOpExec private[scan] ( + descString: String +) extends OperatorExecutor { + private val desc: InputFileScanSourceOpDesc = + objectMapper.readValue(descString, classOf[InputFileScanSourceOpDesc]) + + override def processTuple(tuple: Tuple, port: Int): Iterator[TupleLike] = { + val fileName = + FileResolver.resolve(tuple.getFields.collectFirst { case s: String => s }.get).toASCIIString Review Comment: `tuple.getFields.collectFirst { case s: String => s }.get` will throw `NoSuchElementException` if the input tuple has no String fields, and it can silently pick the wrong field if the tuple contains multiple String attributes. Prefer explicitly reading a specific field (e.g., first field or a configured attribute name) and return a clear error if it’s missing or not a String. ```suggestion val inputFilePath = tuple.getFields.headOption match { case Some(filePath: String) => filePath case Some(value) => throw new IllegalArgumentException( s"Expected the first input tuple field to be a String file path, but found ${value.getClass.getSimpleName}." ) case None => throw new IllegalArgumentException( "Expected the input tuple to contain a file path in the first field, but the tuple has no fields." ) } val fileName = FileResolver.resolve(inputFilePath).toASCIIString ``` -- 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]
