public class ContextManager extends Object
StreamSerDeboth use this ContextManager to look up required information. This call to initialize happens both in the process that launches the Hive job (explore service), and in the mapreduce job that was launched. When called from a mapreduce job, we need to create a DatasetFramework, StreamAdmin, and ZKClientService. This is done by deserializing CDAP's configuration from the Hadoop Configuration, creating an injector, and instantiating those object. When called from the explore service, we don't want to instantiate everything all over again for every query, especially since Hive calls initialize multiple times per query for some reason. In that scenario, the explore service calls
saveContext(DatasetFramework, StreamAdmin, SystemDatasetInstantiatorFactory, AuthorizationEnforcer, AuthenticationContext)when it starts up, in order to cache the Context. Since there is no way for the SerDe to know if it's in a mapreduce job or in the explore service, it relies on whether the Context has been cached to determine whether to create a new Context.
|Modifier and Type||Class and Description|
Contains DatasetFramework object and StreamAdmin object required to run Hive queries in MapReduce jobs.
|Constructor and Description|
|Modifier and Type||Method and Description|
If a context was saved using
Create and save a context, so that any call to
public static void saveContext(DatasetFramework datasetFramework, StreamAdmin streamAdmin, SystemDatasetInstantiatorFactory datasetInstantiatorFactory, AuthorizationEnforcer authorizationEnforcer, AuthenticationContext authenticationContext)
getContext(Configuration)that is made in this jvm will return the context created from this call.
@Nullable public static ContextManager.Context getContext(@Nullable org.apache.hadoop.conf.Configuration conf) throws IOException
saveContext(DatasetFramework, StreamAdmin, SystemDatasetInstantiatorFactory, AuthorizationEnforcer, AuthenticationContext), returns the saved context. This is what happens in the Explore service. If no context was saved and the conf is not null, creates a context and returns it. The context must be closed by the caller. The context created will not be saved, meaning the next time this method is called, a new context will be created. This is what happens in map reduce jobs launched by Hive. If no context was saved and the conf is null, null is returned. The
confparam is expected to contain serialized
Configurationobjects, as well as transaction information.
conf- configuration used to create a context, if necessary. If it is null, return the saved context, which can also be null.
IOException- when the configuration does not contain the required settings to create the context
Copyright © 2018 Cask Data, Inc.. All rights reserved.