Skip to content

Commit

Permalink
apacheGH-42243: [Swift] Update isValidBuilderType to not required ins…
Browse files Browse the repository at this point in the history
…tance of type (apache#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: apache#42243

Authored-by: Alva Bandy <[email protected]>
Signed-off-by: Sutou Kouhei <[email protected]>
  • Loading branch information
abandy authored Jun 21, 2024
1 parent c9a735a commit cb1f9b7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 30 deletions.
3 changes: 1 addition & 2 deletions swift/Arrow/Sources/Arrow/ArrowArrayBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down
56 changes: 28 additions & 28 deletions swift/Arrow/Tests/ArrowTests/ArrayBuilderTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit cb1f9b7

Please sign in to comment.