in spark/sql/dataframe.go [1456:1505]
func (df *dataFrameImpl) Replace(ctx context.Context,
toReplace []types.PrimitiveTypeLiteral, values []types.PrimitiveTypeLiteral, cols ...string,
) (DataFrame, error) {
if len(toReplace) != len(values) {
return nil, sparkerrors.WithType(fmt.Errorf(
"toReplace and values must have the same length"), sparkerrors.InvalidArgumentError)
}
toReplaceExprs := make([]*proto.Expression, 0, len(toReplace))
for _, c := range toReplace {
expr, err := c.ToProto(ctx)
if err != nil {
return nil, err
}
toReplaceExprs = append(toReplaceExprs, expr)
}
valuesExprs := make([]*proto.Expression, 0, len(values))
for _, c := range values {
expr, err := c.ToProto(ctx)
if err != nil {
return nil, err
}
valuesExprs = append(valuesExprs, expr)
}
// Create a list of NAReplace expressions.
replacements := make([]*proto.NAReplace_Replacement, 0, len(toReplace))
for i := 0; i < len(toReplace); i++ {
replacement := &proto.NAReplace_Replacement{
OldValue: toReplaceExprs[i].GetLiteral(),
NewValue: valuesExprs[i].GetLiteral(),
}
replacements = append(replacements, replacement)
}
rel := &proto.Relation{
Common: &proto.RelationCommon{
PlanId: newPlanId(),
},
RelType: &proto.Relation_Replace{
Replace: &proto.NAReplace{
Input: df.relation,
Replacements: replacements,
Cols: cols,
},
},
}
return NewDataFrame(df.session, rel), nil
}