Analytic Server Context
The Context provides support for the Analytic Server context interface for interaction with the 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() : SparkContextReturns the Pyspark python
SQLContext
instance:cxt.getSparkSQLContext() : SQLContextReturns
True to describe whether the execution is made only to compute the
output data model. Otherwise returns
False:cxt.isComputeDataModelOnly() : BooleanReturns
True if the script is running in the Spark environment. Currently, it
always returns True:cxt.isSparkExecution() : BooleanLoads input data from the upstream temporary file and generates the
pyspark.sql.DataFrame
instance:cxt.getSparkInputData() : DataFrameReturns a
pyspark.sql.StructType instance generated from the input data model.
Returns None if the input data model does not
exist:cxt.getSparkInputSchema() : StructTypeSerializes the output data frame into Analytic Server context and returns the
context:
cxt.setSparkOutputData( outDF) : AnalyticServerContextParameter:
outDF (DataFrame) :The output data frame value
Exceptions:
DataOutputNotSupported :If this interface is invoked in the functionpyspark:buildmodelASContextException :If the output data frame isNoneInconsistentOutputDataModel :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) : AnalyticServerContextParameter:
outSchema(StructType) :The outputStructTypeobject
Exceptions:
ASContextException :If the output schema instance isNoneInconsistentOutputDataModel :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) : AnalyticServerContextThe
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 valuepath (string) :location of model building output string pathmimetype (string, optional) :the MIME type of the content
Exceptions:
ModelOutputNotSupported :When not invoking this API from thepyspark:buildmodelfunctionKeyError :If the key attribute isNoneor 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) : AnalyticServerContextParameters:
key (string) :key string valuevalue (string) :the model metadata string valuemimetype (string, optional) :the MIME type of the content
Exceptions:
ModelOutputNotSupported :When not invoking this API from thepyspark:buildmodelfunctionKeyError :If the key attribute isNoneor 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() : stringException:
ModelOutputNotSupported :When not invoking this API from thepyspark:buildmodelfunction
Returns the location of the model which matches the input
key:
cxt.getModelContentToPath(key) : stringParameter:
key (string) :key string value
Exceptions:
ModelInputNotSupported :When not invoking this API from thepyspark:applymodelfunctionKeyError :If the key attribute isNoneor the string is emptyIncompatibleModelContentType :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) : stringParameter:
key (string) :key string value
Exceptions:
ModelInputNotSupported :When not invoking this API from thepyspark:applymodelfunctionKeyError :If the key attribute isNone, or the string is empty, or the key does not existIncompatibleModelContentType :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) : stringParameter:
key (string) :key string value
Exceptions:
ModelInputNotSupported :When not invoking this API from thepyspark:applymodelfunctionKeyError :If the key attribute isNone, or the string is empty, or the key does not exist