| 2212 | } |
| 2213 | |
| 2214 | bool insertIntoSharedData(WriteBuffer & buf, const typename JSONParser::Element & element, const JSONExtractInsertSettings & insert_settings, const FormatSettings & format_settings, String & error, MutableColumnPtr & tmp_dynamic_column) const |
| 2215 | { |
| 2216 | /// Fast track where we process simple data types explicitly and serialize them into |
| 2217 | /// shared data without inserting value into Dynamic column with subsequent binary serialization. |
| 2218 | switch (element.type()) |
| 2219 | { |
| 2220 | case ElementType::BOOL: |
| 2221 | { |
| 2222 | encodeDataType(getDataTypesCache().getType("Bool"), buf); |
| 2223 | writeBinary(element.getBool(), buf); |
| 2224 | return true; |
| 2225 | } |
| 2226 | case ElementType::INT64: |
| 2227 | { |
| 2228 | encodeDataType(getDataTypesCache().getType("Int64"), buf); |
| 2229 | writeBinaryLittleEndian(element.getInt64(), buf); |
| 2230 | return true; |
| 2231 | } |
| 2232 | case ElementType::UINT64: |
| 2233 | { |
| 2234 | encodeDataType(getDataTypesCache().getType("UInt64"), buf); |
| 2235 | writeBinaryLittleEndian(element.getUInt64(), buf); |
| 2236 | return true; |
| 2237 | } |
| 2238 | case ElementType::DOUBLE: |
| 2239 | { |
| 2240 | encodeDataType(getDataTypesCache().getType("Float64"), buf); |
| 2241 | writeBinaryLittleEndian(element.getDouble(), buf); |
| 2242 | return true; |
| 2243 | } |
| 2244 | case ElementType::STRING: |
| 2245 | { |
| 2246 | std::string_view data = element.getString(); |
| 2247 | |
| 2248 | if (!format_settings.try_infer_dates && !format_settings.try_infer_datetimes) |
| 2249 | { |
| 2250 | encodeDataType(getDataTypesCache().getType("String"), buf); |
| 2251 | writeStringBinary(data, buf); |
| 2252 | return true; |
| 2253 | } |
| 2254 | |
| 2255 | if (format_settings.try_infer_dates) |
| 2256 | { |
| 2257 | DayNum date; |
| 2258 | if (tryInferDateFromString(data, date)) |
| 2259 | { |
| 2260 | encodeDataType(getDataTypesCache().getType("Date"), buf); |
| 2261 | writeBinaryLittleEndian(static_cast<UInt16>(date), buf); |
| 2262 | return true; |
| 2263 | } |
| 2264 | } |
| 2265 | |
| 2266 | if (format_settings.try_infer_datetimes && !format_settings.try_infer_datetimes_only_datetime64) |
| 2267 | { |
| 2268 | time_t value = 0; |
| 2269 | if (tryInferDateTimeFromString(data, value, format_settings, time_zone_for_schema_inference, utc_time_zone_for_schema_inference)) |
| 2270 | { |
| 2271 | encodeDataType(getDataTypesCache().getType("DateTime"), buf); |
nothing calls this directly
no test coverage detected