MCPcopy Create free account
hub / github.com/apache/arrow / PrimitiveNode

Method PrimitiveNode

cpp/src/parquet/schema.cc:129–240  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

127// Primitive node
128
129PrimitiveNode::PrimitiveNode(const std::string& name, Repetition::type repetition,
130 Type::type type, ConvertedType::type converted_type,
131 int length, int precision, int scale, int id)
132 : Node(Node::PRIMITIVE, name, repetition, converted_type, id),
133 physical_type_(type),
134 type_length_(length) {
135 std::stringstream ss;
136
137 // PARQUET-842: In an earlier revision, decimal_metadata_.isset was being
138 // set to true, but Impala will raise an incompatible metadata in such cases
139 memset(&decimal_metadata_, 0, sizeof(decimal_metadata_));
140
141 // Check if the physical and logical types match
142 // Mapping referred from Apache parquet-mr as on 2016-02-22
143 switch (converted_type) {
144 case ConvertedType::NONE:
145 // Logical type not set
146 break;
147 case ConvertedType::UTF8:
148 case ConvertedType::JSON:
149 case ConvertedType::BSON:
150 if (type != Type::BYTE_ARRAY) {
151 ss << ConvertedTypeToString(converted_type);
152 ss << " can only annotate BYTE_ARRAY fields";
153 throw ParquetException(ss.str());
154 }
155 break;
156 case ConvertedType::DECIMAL:
157 if ((type != Type::INT32) && (type != Type::INT64) && (type != Type::BYTE_ARRAY) &&
158 (type != Type::FIXED_LEN_BYTE_ARRAY)) {
159 ss << "DECIMAL can only annotate INT32, INT64, BYTE_ARRAY, and FIXED";
160 throw ParquetException(ss.str());
161 }
162 if (precision <= 0) {
163 ss << "Invalid DECIMAL precision: " << precision
164 << ". Precision must be a number between 1 and 38 inclusive";
165 throw ParquetException(ss.str());
166 }
167 if (scale < 0) {
168 ss << "Invalid DECIMAL scale: " << scale
169 << ". Scale must be a number between 0 and precision inclusive";
170 throw ParquetException(ss.str());
171 }
172 if (scale > precision) {
173 ss << "Invalid DECIMAL scale " << scale;
174 ss << " cannot be greater than precision " << precision;
175 throw ParquetException(ss.str());
176 }
177 decimal_metadata_.isset = true;
178 decimal_metadata_.precision = precision;
179 decimal_metadata_.scale = scale;
180 break;
181 case ConvertedType::DATE:
182 case ConvertedType::TIME_MILLIS:
183 case ConvertedType::UINT_8:
184 case ConvertedType::UINT_16:
185 case ConvertedType::UINT_32:
186 case ConvertedType::INT_8:

Callers

nothing calls this directly

Calls 11

ConvertedTypeToStringFunction · 0.85
ParquetExceptionFunction · 0.85
ThrowInvalidLogicalTypeFunction · 0.85
TypeToStringFunction · 0.85
strMethod · 0.80
MakeFunction · 0.70
is_nestedMethod · 0.45
is_compatibleMethod · 0.45
is_applicableMethod · 0.45
ToConvertedTypeMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected