This is an automated email from the ASF dual-hosted git repository.
kou pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new cb1f9b70c9 GH-42243: [Swift] Update isValidBuilderType to not required
instance of type (#42244)
cb1f9b70c9 is described below
commit cb1f9b70c9d64b38faafde3cb32202d0ab515ae7
Author: abandy <[email protected]>
AuthorDate: Fri Jun 21 18:16:57 2024 -0400
GH-42243: [Swift] Update isValidBuilderType to not required instance of
type (#42244)
### Rationale for this change
isValidBuilderType should take a Type and not require an instance of a type
in order to validate.
### What changes are included in this PR?
Updated isValidBuilderType to take a Type instead of an instance.
### Are these changes tested?
Yes
* GitHub Issue: #42243
Authored-by: Alva Bandy <[email protected]>
Signed-off-by: Sutou Kouhei <[email protected]>
---
swift/Arrow/Sources/Arrow/ArrowArrayBuilder.swift | 3 +-
.../Arrow/Tests/ArrowTests/ArrayBuilderTest.swift | 56 +++++++++++-----------
2 files changed, 29 insertions(+), 30 deletions(-)
diff --git a/swift/Arrow/Sources/Arrow/ArrowArrayBuilder.swift
b/swift/Arrow/Sources/Arrow/ArrowArrayBuilder.swift
index 38e6e457f4..dc80f52f8e 100644
--- a/swift/Arrow/Sources/Arrow/ArrowArrayBuilder.swift
+++ b/swift/Arrow/Sources/Arrow/ArrowArrayBuilder.swift
@@ -152,8 +152,7 @@ public class ArrowArrayBuilders {
}
}
- public static func isValidBuilderType<T>(_: T) -> Bool {
- let type = T.self
+ public static func isValidBuilderType<T>(_ type: T.Type) -> Bool {
return type == Int8?.self || type == Int16?.self ||
type == Int32?.self || type == Int64?.self ||
type == UInt8?.self || type == UInt16?.self ||
diff --git a/swift/Arrow/Tests/ArrowTests/ArrayBuilderTest.swift
b/swift/Arrow/Tests/ArrowTests/ArrayBuilderTest.swift
index 965e4ed278..42e167f01f 100644
--- a/swift/Arrow/Tests/ArrowTests/ArrayBuilderTest.swift
+++ b/swift/Arrow/Tests/ArrowTests/ArrayBuilderTest.swift
@@ -20,35 +20,35 @@ import XCTest
final class ArrayBuilderTests: XCTestCase {
func testIsValidTypeForBuilder() throws {
- XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(Int8(0)))
- XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(Int16(0)))
- XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(Int32(0)))
- XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(Int64(0)))
- XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(UInt8(0)))
- XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(UInt16(0)))
- XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(UInt32(0)))
- XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(UInt64(0)))
- XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(Float(0)))
- XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(Double(0)))
- XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(Date.now))
- XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(true))
- XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(Int8?(0)))
- XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(Int16?(0)))
- XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(Int32?(0)))
- XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(Int64?(0)))
- XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(UInt8?(0)))
- XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(UInt16?(0)))
- XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(UInt32?(0)))
- XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(UInt64?(0)))
- XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(Float?(0)))
- XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(Double?(0)))
- XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(Date?(Date.now)))
- XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(Bool?(true)))
+ XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(UInt8.self))
+ XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(Int16.self))
+ XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(Int32.self))
+ XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(Int64.self))
+ XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(UInt8.self))
+ XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(UInt16.self))
+ XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(UInt32.self))
+ XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(UInt64.self))
+ XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(Float.self))
+ XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(Double.self))
+ XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(Date.self))
+ XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(Bool.self))
+ XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(Int8?.self))
+ XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(Int16?.self))
+ XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(Int32?.self))
+ XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(Int64?.self))
+ XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(UInt8?.self))
+ XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(UInt16?.self))
+ XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(UInt32?.self))
+ XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(UInt64?.self))
+ XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(Float?.self))
+ XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(Double?.self))
+ XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(Date?.self))
+ XCTAssertTrue(ArrowArrayBuilders.isValidBuilderType(Bool?.self))
- XCTAssertFalse(ArrowArrayBuilders.isValidBuilderType(Int(0)))
- XCTAssertFalse(ArrowArrayBuilders.isValidBuilderType(UInt(0)))
- XCTAssertFalse(ArrowArrayBuilders.isValidBuilderType(Int?(0)))
- XCTAssertFalse(ArrowArrayBuilders.isValidBuilderType(UInt?(0)))
+ XCTAssertFalse(ArrowArrayBuilders.isValidBuilderType(Int.self))
+ XCTAssertFalse(ArrowArrayBuilders.isValidBuilderType(UInt.self))
+ XCTAssertFalse(ArrowArrayBuilders.isValidBuilderType(Int?.self))
+ XCTAssertFalse(ArrowArrayBuilders.isValidBuilderType(UInt?.self))
}
func testLoadArrayBuilders() throws {