Skip to content

Commit ca9611c

Browse files
Praveen2112dain
authored andcommitted
Compute estimated size directly from slice
When parsing a JSON using Presto's parseJson we compute estimated size of output by populating byte[] from Slice which is not required as we could fetch the same from the length of the Slice
1 parent 435329d commit ca9611c

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

presto-main/src/main/java/io/prestosql/operator/scalar/JsonFunctions.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@ public static Slice jsonParse(@SqlType("varchar(x)") Slice slice)
143143
// If you make changes to this function (e.g. use parse JSON string into some internal representation),
144144
// make sure `$internal$json_string_to_array/map/row_cast` is changed accordingly.
145145
try (JsonParser parser = createJsonParser(JSON_FACTORY, slice)) {
146-
byte[] in = slice.getBytes();
147-
SliceOutput dynamicSliceOutput = new DynamicSliceOutput(in.length);
146+
SliceOutput dynamicSliceOutput = new DynamicSliceOutput(slice.length());
148147
SORTED_MAPPER.writeValue((OutputStream) dynamicSliceOutput, SORTED_MAPPER.readValue(parser, Object.class));
149148
// nextToken() returns null if the input is parsed correctly,
150149
// but will throw an exception if there are trailing characters.

0 commit comments

Comments
 (0)