1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements. See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership. The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License. You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied. See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18#include <cstdint>
19#include <memory>
20#include <string>
21#include <vector>
22
23#include <gtest/gtest.h>
24
25#include "arrow/stl.h"
26#include "arrow/type.h"
27
28namespace arrow {
29namespace stl {
30
31TEST(TestSchemaFromTuple, PrimitiveTypesVector) {
32 Schema expected_schema(
33 {field("column1", int8(), false), field("column2", int16(), false),
34 field("column3", int32(), false), field("column4", int64(), false),
35 field("column5", uint8(), false), field("column6", uint16(), false),
36 field("column7", uint32(), false), field("column8", uint64(), false),
37 field("column9", boolean(), false), field("column10", utf8(), false)});
38
39 std::shared_ptr<Schema> schema =
40 SchemaFromTuple<std::tuple<int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t,
41 uint32_t, uint64_t, bool, std::string>>::
42 MakeSchema(std::vector<std::string>({"column1", "column2", "column3", "column4",
43 "column5", "column6", "column7", "column8",
44 "column9", "column10"}));
45 ASSERT_TRUE(expected_schema.Equals(*schema));
46}
47
48TEST(TestSchemaFromTuple, PrimitiveTypesTuple) {
49 Schema expected_schema(
50 {field("column1", int8(), false), field("column2", int16(), false),
51 field("column3", int32(), false), field("column4", int64(), false),
52 field("column5", uint8(), false), field("column6", uint16(), false),
53 field("column7", uint32(), false), field("column8", uint64(), false),
54 field("column9", boolean(), false), field("column10", utf8(), false)});
55
56 std::shared_ptr<Schema> schema = SchemaFromTuple<
57 std::tuple<int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t,
58 bool, std::string>>::MakeSchema(std::make_tuple("column1", "column2",
59 "column3", "column4",
60 "column5", "column6",
61 "column7", "column8",
62 "column9", "column10"));
63 ASSERT_TRUE(expected_schema.Equals(*schema));
64}
65
66TEST(TestSchemaFromTuple, SimpleList) {
67 Schema expected_schema({field("column1", list(utf8()), false)});
68 std::shared_ptr<Schema> schema =
69 SchemaFromTuple<std::tuple<std::vector<std::string>>>::MakeSchema({"column1"});
70
71 ASSERT_TRUE(expected_schema.Equals(*schema));
72}
73
74TEST(TestSchemaFromTuple, NestedList) {
75 Schema expected_schema({field("column1", list(list(boolean())), false)});
76 std::shared_ptr<Schema> schema =
77 SchemaFromTuple<std::tuple<std::vector<std::vector<bool>>>>::MakeSchema(
78 {"column1"});
79
80 ASSERT_TRUE(expected_schema.Equals(*schema));
81}
82
83} // namespace stl
84} // namespace arrow
85