Copilot commented on code in PR #190: URL: https://github.com/apache/arrow-swift/pull/190#discussion_r3721404776
########## Tests/ArrowTests/TimeBitWidthTests.swift: ########## @@ -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. + +import XCTest +import FlatBuffers +@testable import Arrow + +final class TimeBitWidthTests: XCTestCase { + private func timeBitWidth(_ arrowType: ArrowType) throws -> Int32 { + let schema = ArrowSchema.Builder() + .addField("col", type: arrowType, isNullable: false) + .finish() + let writer = ArrowWriter() + let data: Data + switch writer.toMessage(schema) { + case .success(let result): data = result + case .failure(let error): throw error + } Review Comment: This manual `switch` to unwrap a `Result` can be simplified and made more idiomatic/compact by using `try writer.toMessage(schema).get()`, which also preserves the same error propagation behavior. ########## Sources/Arrow/ArrowWriterHelper.swift: ########## @@ -101,6 +101,7 @@ func toFBType( // swiftlint:disable:this cyclomatic_complexity function_body_len let startOffset = org_apache_arrow_flatbuf_Time.startTime(&fbb) if let timeType = arrowType as? ArrowTypeTime64 { org_apache_arrow_flatbuf_Time.add(unit: timeType.unit == .microseconds ? .microsecond : .nanosecond, &fbb) + org_apache_arrow_flatbuf_Time.add(bitWidth: 64, &fbb) Review Comment: For clarity and to match the FlatBuffers schema type (typically `Int32` for `bitWidth`), consider making the literal explicit (e.g., `Int32(64)`). This avoids any ambiguity around integer literal inference and documents the intended wire type. ########## Tests/ArrowTests/TimeBitWidthTests.swift: ########## @@ -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. + +import XCTest +import FlatBuffers +@testable import Arrow + +final class TimeBitWidthTests: XCTestCase { + private func timeBitWidth(_ arrowType: ArrowType) throws -> Int32 { + let schema = ArrowSchema.Builder() + .addField("col", type: arrowType, isNullable: false) + .finish() + let writer = ArrowWriter() + let data: Data + switch writer.toMessage(schema) { + case .success(let result): data = result + case .failure(let error): throw error + } + var buffer = ByteBuffer(data: data) + let message: org_apache_arrow_flatbuf_Message = getRoot(byteBuffer: &buffer) + let fbSchema: org_apache_arrow_flatbuf_Schema = message.header(type: org_apache_arrow_flatbuf_Schema.self)! + let field = fbSchema.fields(at: 0)! + let timeType: org_apache_arrow_flatbuf_Time = field.type(type: org_apache_arrow_flatbuf_Time.self)! Review Comment: These force-unwraps can crash the entire test run (not just fail the test) if the message/header/field parsing changes or data is malformed. Prefer `guard let ... else { XCTFail(\"...\"); return ... }` (or `XCTUnwrap`) to produce a clean test failure with a useful diagnostic. -- 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]
