| 1088 | } |
| 1089 | |
| 1090 | Result<std::shared_ptr<DataType>> GetArrowType(const liborc::Type* type) { |
| 1091 | // When subselecting fields on read, liborc will set some nodes to nullptr, |
| 1092 | // so we need to check for nullptr before progressing |
| 1093 | if (type == nullptr) { |
| 1094 | return null(); |
| 1095 | } |
| 1096 | liborc::TypeKind kind = type->getKind(); |
| 1097 | const int subtype_count = static_cast<int>(type->getSubtypeCount()); |
| 1098 | |
| 1099 | switch (kind) { |
| 1100 | case liborc::BOOLEAN: |
| 1101 | return boolean(); |
| 1102 | case liborc::BYTE: |
| 1103 | return int8(); |
| 1104 | case liborc::SHORT: |
| 1105 | return int16(); |
| 1106 | case liborc::INT: |
| 1107 | return int32(); |
| 1108 | case liborc::LONG: |
| 1109 | return int64(); |
| 1110 | case liborc::FLOAT: |
| 1111 | return float32(); |
| 1112 | case liborc::DOUBLE: |
| 1113 | return float64(); |
| 1114 | case liborc::CHAR: |
| 1115 | case liborc::VARCHAR: |
| 1116 | case liborc::STRING: |
| 1117 | return utf8(); |
| 1118 | case liborc::BINARY: |
| 1119 | return binary(); |
| 1120 | case liborc::TIMESTAMP: |
| 1121 | // Values of TIMESTAMP type are stored in the writer timezone in the Orc file. |
| 1122 | // Values are read back in the reader timezone. However, the writer timezone |
| 1123 | // information in the Orc stripe footer is optional and may be missing. What is |
| 1124 | // more, stripes in the same Orc file may have different writer timezones (though |
| 1125 | // unlikely). So we cannot tell the exact timezone of values read back in the |
| 1126 | // arrow::TimestampArray. In the adapter implementations, we set both writer and |
| 1127 | // reader timezone to UTC to avoid any conversion so users can get the same values |
| 1128 | // as written. To get rid of this burden, TIMESTAMP_INSTANT type is always preferred |
| 1129 | // over TIMESTAMP type. |
| 1130 | return timestamp(TimeUnit::NANO); |
| 1131 | case liborc::TIMESTAMP_INSTANT: |
| 1132 | // Values of TIMESTAMP_INSTANT type are stored in the UTC timezone in the ORC file. |
| 1133 | // Both read and write use the UTC timezone without any conversion. |
| 1134 | return timestamp(TimeUnit::NANO, "UTC"); |
| 1135 | case liborc::DATE: |
| 1136 | return date32(); |
| 1137 | case liborc::DECIMAL: { |
| 1138 | const int precision = static_cast<int>(type->getPrecision()); |
| 1139 | const int scale = static_cast<int>(type->getScale()); |
| 1140 | if (precision == 0) { |
| 1141 | // In HIVE 0.11/0.12 precision is set as 0, but means max precision |
| 1142 | return decimal128(38, 6); |
| 1143 | } |
| 1144 | return decimal128(precision, scale); |
| 1145 | } |
| 1146 | case liborc::LIST: { |
| 1147 | if (subtype_count != 1) { |
nothing calls this directly
no test coverage detected