@@ -1261,12 +1261,6 @@ bool Histogram_binary::parse(MEM_ROOT *mem_root, Histogram_type type_arg, const
1261
1261
*/
1262
1262
void Histogram_binary::serialize (Field *field)
1263
1263
{
1264
- if (get_type () == JSON)
1265
- {
1266
- field->store ((char *)get_values (), strlen ((char *)get_values ()),
1267
- &my_charset_bin);
1268
- }
1269
- else
1270
1264
field->store ((char *)get_values (), get_width (), &my_charset_bin);
1271
1265
}
1272
1266
@@ -1287,6 +1281,32 @@ void Histogram_json::init_for_collection(MEM_ROOT *mem_root, Histogram_type htyp
1287
1281
size = (uint8) size_arg;
1288
1282
}
1289
1283
1284
+ bool Histogram_json::parse (MEM_ROOT *mem_root, Histogram_type type_arg, const uchar *ptr, uint size_arg)
1285
+ {
1286
+ size = (uint8) size_arg;
1287
+ type = type_arg;
1288
+ // I think we could use memcpy here, but not sure about how to get the right size
1289
+ // since we can't depend on size_arg (it's zero for json histograms)
1290
+ // also, does it make sense to cast here? or we can modify json_get_array_items
1291
+ // to accept uchar*
1292
+ const char *json = (char *)ptr;
1293
+ int vt;
1294
+ bool result = json_get_array_items (json, json + strlen (json), &vt, hist_buckets);
1295
+ fprintf (stderr," ==============\n " );
1296
+ fprintf (stderr," histogram: %s\n " , json);
1297
+ fprintf (stderr, " json_get_array_items() returned %s\n " , result ? " true" : " false" );
1298
+ fprintf (stderr, " value type after json_get_array_items() is %d\n " , vt);
1299
+ fprintf (stderr, " JSV_BAD_JSON=%d, JSON_VALUE_ARRAY=%d\n " , (int )JSV_BAD_JSON, (int )JSON_VALUE_ARRAY);
1300
+ fprintf (stderr, " hist_buckets.size()=%zu\n " , hist_buckets.size ());
1301
+ return false ;
1302
+ }
1303
+
1304
+ void Histogram_json::serialize (Field *field)
1305
+ {
1306
+ field->store ((char *)get_values (), strlen ((char *)get_values ()),
1307
+ &my_charset_bin);
1308
+ }
1309
+
1290
1310
/*
1291
1311
An object of the class Index_stat is created to read statistical
1292
1312
data on tables from the statistical table table_stat, to update
@@ -1987,9 +2007,9 @@ class Count_distinct_field: public Sql_alloc
1987
2007
@brief
1988
2008
Get the pointer to the histogram built for table_field
1989
2009
*/
1990
- Histogram_binary *get_histogram ()
2010
+ Histogram_base *get_histogram ()
1991
2011
{
1992
- return dynamic_cast <Histogram_binary *>( table_field->collected_stats ->histogram_ ) ;
2012
+ return table_field->collected_stats ->histogram_ ;
1993
2013
}
1994
2014
1995
2015
};
0 commit comments