richardstartin commented on a change in pull request #7820: URL: https://github.com/apache/pinot/pull/7820#discussion_r762856827
########## File path: pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/evaluator/json/JsonPathEvaluators.java ########## @@ -0,0 +1,150 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.pinot.segment.spi.evaluator.json; + +import com.google.common.base.Preconditions; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; +import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Allows registration of a custom {@see JsonPathEvaluator} which can handle custom storage + * functionality also present in a plugin. A default evaluator which can handle all default + * storage types will be provided to delegate to when standard storage types are encountered. + * + * This is an evolving SPI and subject to change. + */ +public final class JsonPathEvaluators { + + private static final Logger LOGGER = LoggerFactory.getLogger(JsonPathEvaluators.class); + + private static final AtomicReferenceFieldUpdater<JsonPathEvaluators, JsonPathEvaluatorProvider> UPDATER = + AtomicReferenceFieldUpdater.newUpdater(JsonPathEvaluators.class, JsonPathEvaluatorProvider.class, "_provider"); + private static final JsonPathEvaluators INSTANCE = new JsonPathEvaluators(); + private static final DefaultProvider DEFAULT_PROVIDER = new DefaultProvider(); + private volatile JsonPathEvaluatorProvider _provider; + + /** + * Registration point to override how JSON paths are evaluated. This should be used + * when a Pinot plugin has special storage capabilities. For instance, imagine a + * plugin with a raw forward index which stores JSON in a binary format which + * pinot-core is unaware of and cannot evaluate JSON paths against (pinot-core only + * understands true JSON documents). Whenever JSON paths are evaluated against this + * custom storage, different storage access operations may be required, and the provided + * {@see JsonPathEvaluator} can inspect the provided {@see ForwardIndexReader} to + * determine whether it is the custom implementation and evaluate the JSON path against + * the binary JSON managed by the custom reader. If it is not the custom implementation, + * then the evaluation should be delegated to the provided delegate. + * + * This prevents the interface {@see ForwardIndexReader} from needing to be able to model + * any plugin storage format, which creates flexibility for the kinds of data structure + * plugins can employ. + * + * @param provider provides {@see JsonPathEvaluator} + * @return true if registration is successful, false otherwise + */ + public static boolean registerProvider(JsonPathEvaluatorProvider provider) { + Preconditions.checkArgument(provider != null, ""); Review comment: I think this is better for a couple of reasons 1. double registration becomes obvious 2. various runtime benefits of the provider being `final` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
