1313 */
1414package com .facebook .presto .operator .scalar ;
1515
16- import com .facebook .airlift .json .JsonObjectMapperProvider ;
17- import com .facebook .presto .common .function .SqlFunctionProperties ;
1816import com .facebook .presto .spi .PrestoException ;
1917import com .fasterxml .jackson .core .JsonFactory ;
2018import com .fasterxml .jackson .core .JsonGenerator ;
2119import com .fasterxml .jackson .core .JsonParseException ;
2220import com .fasterxml .jackson .core .JsonParser ;
2321import com .fasterxml .jackson .core .JsonToken ;
2422import com .fasterxml .jackson .core .io .SerializedString ;
25- import com .fasterxml .jackson .databind .ObjectMapper ;
2623import com .google .common .collect .ImmutableList ;
2724import io .airlift .slice .DynamicSliceOutput ;
2825import io .airlift .slice .Slice ;
2926
3027import java .io .IOException ;
3128import java .io .InputStream ;
32- import java .io .OutputStream ;
3329import java .io .UncheckedIOException ;
3430
3531import static com .facebook .presto .spi .StandardErrorCode .INVALID_FUNCTION_ARGUMENT ;
4238import static com .fasterxml .jackson .core .JsonToken .START_ARRAY ;
4339import static com .fasterxml .jackson .core .JsonToken .START_OBJECT ;
4440import static com .fasterxml .jackson .core .JsonToken .VALUE_NULL ;
45- import static com .fasterxml .jackson .databind .SerializationFeature .ORDER_MAP_ENTRIES_BY_KEYS ;
4641import static io .airlift .slice .Slices .utf8Slice ;
4742import static java .util .Objects .requireNonNull ;
4843
@@ -126,15 +121,13 @@ public final class JsonExtract
126121 private static final JsonFactory JSON_FACTORY = new JsonFactory ()
127122 .disable (CANONICALIZE_FIELD_NAMES );
128123
129- private static final ObjectMapper SORTED_MAPPER = new JsonObjectMapperProvider ().get ().configure (ORDER_MAP_ENTRIES_BY_KEYS , true );
130-
131124 private JsonExtract () {}
132125
133- public static <T > T extract (Slice jsonInput , JsonExtractor <T > jsonExtractor , SqlFunctionProperties properties )
126+ public static <T > T extract (Slice jsonInput , JsonExtractor <T > jsonExtractor )
134127 {
135128 requireNonNull (jsonInput , "jsonInput is null" );
136129 try {
137- return jsonExtractor .extract (jsonInput .getInput (), properties );
130+ return jsonExtractor .extract (jsonInput .getInput ());
138131 }
139132 catch (JsonParseException e ) {
140133 // Return null if we failed to parse something
@@ -163,7 +156,7 @@ public static <T> PrestoJsonExtractor<T> generateExtractor(String path, PrestoJs
163156
164157 public interface JsonExtractor <T >
165158 {
166- T extract (InputStream inputStream , SqlFunctionProperties properties )
159+ T extract (InputStream inputStream )
167160 throws IOException ;
168161 }
169162
@@ -181,11 +174,11 @@ public abstract static class PrestoJsonExtractor<T>
181174 *
182175 * @return the value, or null if not applicable
183176 */
184- abstract T extract (JsonParser jsonParser , SqlFunctionProperties properties )
177+ abstract T extract (JsonParser jsonParser )
185178 throws IOException ;
186179
187180 @ Override
188- public T extract (InputStream inputStream , SqlFunctionProperties properties )
181+ public T extract (InputStream inputStream )
189182 throws IOException
190183 {
191184 try (JsonParser jsonParser = createJsonParser (JSON_FACTORY , inputStream )) {
@@ -194,7 +187,7 @@ public T extract(InputStream inputStream, SqlFunctionProperties properties)
194187 return null ;
195188 }
196189
197- return extract (jsonParser , properties );
190+ return extract (jsonParser );
198191 }
199192 }
200193 }
@@ -221,21 +214,21 @@ public ObjectFieldJsonExtractor(String fieldName, PrestoJsonExtractor<? extends
221214 }
222215
223216 @ Override
224- public T extract (JsonParser jsonParser , SqlFunctionProperties properties )
217+ public T extract (JsonParser jsonParser )
225218 throws IOException
226219 {
227220 if (jsonParser .getCurrentToken () == START_OBJECT ) {
228- return processJsonObject (jsonParser , properties );
221+ return processJsonObject (jsonParser );
229222 }
230223
231224 if (jsonParser .getCurrentToken () == START_ARRAY ) {
232- return processJsonArray (jsonParser , properties );
225+ return processJsonArray (jsonParser );
233226 }
234227
235228 throw new JsonParseException (jsonParser , "Expected a JSON object or array" );
236229 }
237230
238- public T processJsonObject (JsonParser jsonParser , SqlFunctionProperties properties )
231+ public T processJsonObject (JsonParser jsonParser )
239232 throws IOException
240233 {
241234 while (!jsonParser .nextFieldName (fieldName )) {
@@ -251,10 +244,10 @@ public T processJsonObject(JsonParser jsonParser, SqlFunctionProperties properti
251244
252245 jsonParser .nextToken (); // Shift to first token of the value
253246
254- return delegate .extract (jsonParser , properties );
247+ return delegate .extract (jsonParser );
255248 }
256249
257- public T processJsonArray (JsonParser jsonParser , SqlFunctionProperties properties )
250+ public T processJsonArray (JsonParser jsonParser )
258251 throws IOException
259252 {
260253 int currentIndex = 0 ;
@@ -277,15 +270,15 @@ public T processJsonArray(JsonParser jsonParser, SqlFunctionProperties propertie
277270 jsonParser .skipChildren (); // Skip nested structure if currently at the start of one
278271 }
279272
280- return delegate .extract (jsonParser , properties );
273+ return delegate .extract (jsonParser );
281274 }
282275 }
283276
284277 public static class ScalarValueJsonExtractor
285278 extends PrestoJsonExtractor <Slice >
286279 {
287280 @ Override
288- public Slice extract (JsonParser jsonParser , SqlFunctionProperties properties )
281+ public Slice extract (JsonParser jsonParser )
289282 throws IOException
290283 {
291284 JsonToken token = jsonParser .getCurrentToken ();
@@ -303,31 +296,13 @@ public static class JsonValueJsonExtractor
303296 extends PrestoJsonExtractor <Slice >
304297 {
305298 @ Override
306- public Slice extract (JsonParser jsonParser , SqlFunctionProperties properties )
299+ public Slice extract (JsonParser jsonParser )
307300 throws IOException
308301 {
309302 if (!jsonParser .hasCurrentToken ()) {
310303 throw new JsonParseException (jsonParser , "Unexpected end of value" );
311304 }
312- if (!properties .isCanonicalizedJsonExtract ()) {
313- return legacyExtract (jsonParser );
314- }
315- DynamicSliceOutput dynamicSliceOutput = new DynamicSliceOutput (ESTIMATED_JSON_OUTPUT_SIZE );
316- // Write the JSON to output stream with sorted keys
317- SORTED_MAPPER .writeValue ((OutputStream ) dynamicSliceOutput , SORTED_MAPPER .readValue (jsonParser , Object .class ));
318- // nextToken will throw an exception if there are trailing characters.
319- try {
320- jsonParser .nextToken ();
321- }
322- catch (JsonParseException e ) {
323- throw new PrestoException (INVALID_FUNCTION_ARGUMENT , e .getMessage ());
324- }
325- return dynamicSliceOutput .slice ();
326- }
327305
328- public Slice legacyExtract (JsonParser jsonParser )
329- throws IOException
330- {
331306 DynamicSliceOutput dynamicSliceOutput = new DynamicSliceOutput (ESTIMATED_JSON_OUTPUT_SIZE );
332307 try (JsonGenerator jsonGenerator = createJsonGenerator (JSON_FACTORY , dynamicSliceOutput )) {
333308 jsonGenerator .copyCurrentStructure (jsonParser );
@@ -340,7 +315,7 @@ public static class JsonSizeExtractor
340315 extends PrestoJsonExtractor <Long >
341316 {
342317 @ Override
343- public Long extract (JsonParser jsonParser , SqlFunctionProperties properties )
318+ public Long extract (JsonParser jsonParser )
344319 throws IOException
345320 {
346321 if (!jsonParser .hasCurrentToken ()) {
0 commit comments