use of org.jpmml.sparkml.AliasExpression in project jpmml-sparkml by jpmml.
the class SQLTransformerConverter method encodeLogicalPlan.
public static List<Field<?>> encodeLogicalPlan(SparkMLEncoder encoder, LogicalPlan logicalPlan) {
List<Field<?>> result = new ArrayList<>();
List<LogicalPlan> children = JavaConversions.seqAsJavaList(logicalPlan.children());
for (LogicalPlan child : children) {
encodeLogicalPlan(encoder, child);
}
List<Expression> expressions = JavaConversions.seqAsJavaList(logicalPlan.expressions());
for (Expression expression : expressions) {
org.dmg.pmml.Expression pmmlExpression = ExpressionTranslator.translate(encoder, expression);
if (pmmlExpression instanceof FieldRef) {
FieldRef fieldRef = (FieldRef) pmmlExpression;
Field<?> field = ensureField(encoder, fieldRef.getField());
if (field != null) {
result.add(field);
continue;
}
}
FieldName name = null;
if (pmmlExpression instanceof AliasExpression) {
AliasExpression aliasExpression = (AliasExpression) pmmlExpression;
name = FieldName.create(aliasExpression.getName());
} else {
name = FieldNameUtil.create("sql", ExpressionUtil.format(expression));
}
DataType dataType = DatasetUtil.translateDataType(expression.dataType());
OpType opType = ExpressionUtil.getOpType(dataType);
pmmlExpression = AliasExpression.unwrap(pmmlExpression);
Visitor visitor = new AbstractVisitor() {
@Override
public VisitorAction visit(FieldRef fieldRef) {
ensureField(encoder, fieldRef.getField());
return super.visit(fieldRef);
}
};
visitor.applyTo(pmmlExpression);
DerivedField derivedField = encoder.createDerivedField(name, opType, dataType, pmmlExpression);
result.add(derivedField);
}
return result;
}
Aggregations