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

Method PrimitiveNode

cpp/src/parquet/schema.cc:130–241  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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