扩展过程节点属性
通过 "扩展变换" 节点,您可以从流中获取数据,并使用 R 脚本编制或 Python for Spark 脚本编制将变换应用于数据。
Python 以Spark为例
import modeler.api
stream = modeler.script.stream()
node = stream.create("extension_process", "extension_process")
node.setPropertyValue("syntax_type", "Python")
process_script = """
import spss.pyspark.runtime
from pyspark.sql.types import *
cxt = spss.pyspark.runtime.getContext()
if cxt.isComputeDataModelOnly():
_schema = StructType([StructField("Age", LongType(), nullable=True), \
StructField("Sex", StringType(), nullable=True), \
StructField("BP", StringType(), nullable=True), \
StructField("Na", DoubleType(), nullable=True), \
StructField("K", DoubleType(), nullable=True), \
StructField("Drug", StringType(), nullable=True)])
cxt.setSparkOutputSchema(_schema)
else:
df = cxt.getSparkInputData()
print df.dtypes[:]
_newDF = df.select("Age","Sex","BP","Na","K","Drug")
print _newDF.dtypes[:]
cxt.setSparkOutputData(_newDF)
"""
node.setPropertyValue("python_syntax", process_script)
R 示例
node.setPropertyValue("syntax_type", "R")
node.setPropertyValue("r_syntax", """day<-as.Date(modelerData$dob, format="%Y-%m-%d")
next_day<-day + 1
modelerData<-cbind(modelerData,next_day)
var1<-c(fieldName="Next day",fieldLabel="",fieldStorage="date",fieldMeasure="",fieldFormat="",
fieldRole="")
modelerDataModel<-data.frame(modelerDataModel,var1)""")
extensionprocessnode properties |
数据类型 | 属性描述 |
|---|---|---|
syntax_type |
R Python | 指定运行哪种脚本——R或 Python (R为默认值)。 |
r_syntax |
字符串 | 运行R脚本语法。 |
python_syntax |
字符串 | 要运行的 Python 脚本语法。 |
use_batch_size |
标志 | 启用批处理功能。 |
batch_size |
整数 | 指定每批要包含的数据记录数。 |
convert_flags |
|
转换标志字段的选项。 |
convert_missing |
标志 | 用于将缺失值转换为 R 的选项NA值。 |
convert_datetime |
标志 | 可将日期或时间日期格式的变量转换为R日期/时间格式。 |
convert_datetime_class |
|
选项用于指定日期或时间日期格式的变量转换为何种格式。 |