forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
apacheGH-42124: [Swift] Add methods for loading and validating builde…
…r by type (apache#42195) ### Rationale for this change Adding convenience method for loading a builder from a type. This will be used by ArrowEncoder (upcoming PR) to load builders for a class/structs's properties. ### What changes are included in this PR? Two methods have been added to ArrowArrayBuilders: loadBuilder: method for loading a builder for a Type. isValidBuilderType: method for checking if a Type is supported by a builder. ### Are these changes tested? Yes * GitHub Issue: apache#42124 Authored-by: Alva Bandy <abandy@live.com> Signed-off-by: Sutou Kouhei <kou@clear-code.com>
- Loading branch information
Showing
2 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// 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 | ||
@testable import Arrow | ||
|
||
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))) | ||
|
||
XCTAssertFalse(ArrowArrayBuilders.isValidBuilderType(Int(0))) | ||
XCTAssertFalse(ArrowArrayBuilders.isValidBuilderType(UInt(0))) | ||
XCTAssertFalse(ArrowArrayBuilders.isValidBuilderType(Int?(0))) | ||
XCTAssertFalse(ArrowArrayBuilders.isValidBuilderType(UInt?(0))) | ||
} | ||
|
||
func testLoadArrayBuilders() throws { | ||
XCTAssertNotNil(try ArrowArrayBuilders.loadBuilder(Int8.self)) | ||
XCTAssertNotNil(try ArrowArrayBuilders.loadBuilder(Int16.self)) | ||
XCTAssertNotNil(try ArrowArrayBuilders.loadBuilder(Int32.self)) | ||
XCTAssertNotNil(try ArrowArrayBuilders.loadBuilder(Int64.self)) | ||
XCTAssertNotNil(try ArrowArrayBuilders.loadBuilder(UInt8.self)) | ||
XCTAssertNotNil(try ArrowArrayBuilders.loadBuilder(UInt16.self)) | ||
XCTAssertNotNil(try ArrowArrayBuilders.loadBuilder(UInt32.self)) | ||
XCTAssertNotNil(try ArrowArrayBuilders.loadBuilder(UInt64.self)) | ||
XCTAssertNotNil(try ArrowArrayBuilders.loadBuilder(Float.self)) | ||
XCTAssertNotNil(try ArrowArrayBuilders.loadBuilder(Double.self)) | ||
XCTAssertNotNil(try ArrowArrayBuilders.loadBuilder(Date.self)) | ||
XCTAssertNotNil(try ArrowArrayBuilders.loadBuilder(Bool.self)) | ||
XCTAssertNotNil(try ArrowArrayBuilders.loadBuilder(Int8?.self)) | ||
XCTAssertNotNil(try ArrowArrayBuilders.loadBuilder(Int16?.self)) | ||
XCTAssertNotNil(try ArrowArrayBuilders.loadBuilder(Int32?.self)) | ||
XCTAssertNotNil(try ArrowArrayBuilders.loadBuilder(Int64?.self)) | ||
XCTAssertNotNil(try ArrowArrayBuilders.loadBuilder(UInt8?.self)) | ||
XCTAssertNotNil(try ArrowArrayBuilders.loadBuilder(UInt16?.self)) | ||
XCTAssertNotNil(try ArrowArrayBuilders.loadBuilder(UInt32?.self)) | ||
XCTAssertNotNil(try ArrowArrayBuilders.loadBuilder(UInt64?.self)) | ||
XCTAssertNotNil(try ArrowArrayBuilders.loadBuilder(Float?.self)) | ||
XCTAssertNotNil(try ArrowArrayBuilders.loadBuilder(Double?.self)) | ||
XCTAssertNotNil(try ArrowArrayBuilders.loadBuilder(Date?.self)) | ||
XCTAssertNotNil(try ArrowArrayBuilders.loadBuilder(Bool?.self)) | ||
|
||
XCTAssertThrowsError(try ArrowArrayBuilders.loadBuilder(Int.self)) | ||
XCTAssertThrowsError(try ArrowArrayBuilders.loadBuilder(UInt.self)) | ||
XCTAssertThrowsError(try ArrowArrayBuilders.loadBuilder(Int?.self)) | ||
XCTAssertThrowsError(try ArrowArrayBuilders.loadBuilder(UInt?.self)) | ||
} | ||
} |