0 / 0
Analytic Server Context

Analytic Server Context

The Context provides support for the Analytic Server Context interface for interaction with the SPSS Analytic Server.

The Context provides support for the Analytic Server context interface for interaction with SPSS Analytic Server.

AnalyticServerContext Objects

AnalyticServerContext objects set up the context environment which provides several interfaces for interacting with SPSS Analytic Server. An application that wants to construct this context instance must do so using the spss.pyspark.runtime.getContext() interface rather than implementing the interface directly.

Returns the Pyspark python SparkContext instance:
cxt.getSparkContext() : SparkContext
Returns the Pyspark python SQLContext instance:
cxt.getSparkSQLContext() : SQLContext
Returns True to describe whether the execution is made only to compute the output data model. Otherwise returns False:
cxt.isComputeDataModelOnly() : Boolean
Returns True if the script is running in the Spark environment. Currently, it always returns True:
cxt.isSparkExecution() : Boolean
Loads input data from the upstream temporary file and generates the pyspark.sql.DataFrame instance:
cxt.getSparkInputData() : DataFrame
Returns a pyspark.sql.StructType instance generated from the input data model. Returns None if the input data model does not exist:
cxt.getSparkInputSchema() : StructType
Serializes the output data frame into Analytic Server context and returns the context:
cxt.setSparkOutputData( outDF) : AnalyticServerContext
Parameter:
  • outDF (DataFrame) : The output data frame value
Exceptions:
  • DataOutputNotSupported : If this interface is invoked in the function pyspark:buildmodel
  • ASContextException : If the output data frame is None
  • InconsistentOutputDataModel : The field names and storage type information common to both objects is inconsistent
Converts the outSchema StructType instance into a data model, serializes it into the Analytic Server context, and returns the context:
cxt.setSparkOutputSchema(outSchema) : AnalyticServerContext
Parameter:
  • outSchema(StructType) : The output StructType object
Exceptions:
  • ASContextException : If the output schema instance is None
  • InconsistentOutputDataModel : The field names and storage type information common to both objects is inconsistent
Stores the location of model building output to the Analytic Server context and returns the context:
cxt.setModelContentFromPath(key, path, mimetype=None) : AnalyticServerContext
The path can be a directory path which should use the cxt.createTemporaryFolder() API to generate , when everything under the directory is packaged up as model content.
Parameters:
  • key (string) : key string value
  • path (string) : location of model building output string path
  • mimetype (string, optional) : the MIME type of the content
Exceptions:
  • ModelOutputNotSupported : When not invoking this API from the pyspark:buildmodel function
  • KeyError : If the key attribute is None or the string is empty
Stores the model building content, metadata, or other attributes to the Analytic Server context and returns the context:
cxt.setModelContentFromString(key, value, mimetype=None) : AnalyticServerContext
Parameters:
  • key (string) : key string value
  • value (string) : the model metadata string value
  • mimetype (string, optional) : the MIME type of the content
Exceptions:
  • ModelOutputNotSupported : When not invoking this API from the pyspark:buildmodel function
  • KeyError : If the key attribute is None or the string is empty
Returns the temporary folder location that is managed by Analytic Server; this can be used to store the model content:
cxt.createTemporaryFolder() : string
Exception:
  • ModelOutputNotSupported : When not invoking this API from the pyspark:buildmodel function
Returns the location of the model which matches the input key:
cxt.getModelContentToPath(key) : string
Parameter:
  • key (string) : key string value
Exceptions:
  • ModelInputNotSupported : When not invoking this API from the pyspark:applymodel function
  • KeyError : If the key attribute is None or the string is empty
  • IncompatibleModelContentType : If the model content type is not a container
Returns the model content, metadata of the model, or other model attributes which match the input key:
cxt.getModelContentToString(key) : string
Parameter:
  • key (string) : key string value
Exceptions:
  • ModelInputNotSupported : When not invoking this API from the pyspark:applymodel function
  • KeyError : If the key attribute is None, or the string is empty, or the key does not exist
  • IncompatibleModelContentType : If the model content type is not consistent
Returns the mime-type assigned to the input key. It returns None if the specified content has no mime type:
cxt.getModelContentMimeType(key) : string
Parameter:
  • key (string) : key string value
Exceptions:
  • ModelInputNotSupported : When not invoking this API from the pyspark:applymodel function
  • KeyError : If the key attribute is None, or the string is empty, or the key does not exist
Generative AI search and answer
These answers are generated by a large language model in watsonx.ai based on content from the product documentation. Learn more