@@ -249,34 +249,41 @@ private RelationPlan addColumnMasks(Table table, RelationPlan plan, SqlPlannerCo
249249 {
250250 Map <String , Expression > columnMasks = analysis .getColumnMasks (table );
251251
252+ PlanBuilder planBuilder = initializePlanBuilder (plan );
252253 List <VariableReferenceExpression > mappings = plan .getFieldMappings ();
253- TranslationMap translations = new TranslationMap (plan , analysis , lambdaDeclarationToVariableMap );
254- translations .setFieldMappings (mappings );
254+ ImmutableList .Builder <VariableReferenceExpression > newMappings = ImmutableList .builder ();
255255
256- PlanBuilder planBuilder = new PlanBuilder (translations , plan .getRoot ());
256+ Assignments .Builder assignments = new Assignments .Builder ();
257+ for (VariableReferenceExpression variableReferenceExpression : planBuilder .getRoot ().getOutputVariables ()) {
258+ assignments .put (variableReferenceExpression , rowExpression (new SymbolReference (variableReferenceExpression .getName ()), context ));
259+ }
257260
258261 for (int i = 0 ; i < plan .getDescriptor ().getAllFieldCount (); i ++) {
259262 Field field = plan .getDescriptor ().getFieldByIndex (i );
260263
264+ VariableReferenceExpression fieldMapping ;
265+ RowExpression rowExpression ;
261266 if (field .getName ().isPresent () && columnMasks .containsKey (field .getName ().get ())) {
262267 Expression mask = columnMasks .get (field .getName ().get ());
263-
264268 planBuilder = subqueryPlanner .handleSubqueries (planBuilder , mask , mask , context );
265-
266- Map <VariableReferenceExpression , RowExpression > assignments = new LinkedHashMap <>();
267- for (VariableReferenceExpression variableReferenceExpression : planBuilder .getRoot ().getOutputVariables ()) {
268- assignments .put (variableReferenceExpression , rowExpression (new SymbolReference (variableReferenceExpression .getName ()), context ));
269- }
270- assignments .put (mappings .get (i ), rowExpression (translations .rewrite (mask ), context ));
271-
272- planBuilder = planBuilder .withNewRoot (new ProjectNode (
273- idAllocator .getNextId (),
274- planBuilder .getRoot (),
275- Assignments .copyOf (assignments )));
269+ fieldMapping = newVariable (variableAllocator , field );
270+ rowExpression = rowExpression (planBuilder .rewrite (mask ), context );
276271 }
272+ else {
273+ fieldMapping = mappings .get (i );
274+ rowExpression = rowExpression (createSymbolReference (fieldMapping ), context );
275+ }
276+
277+ assignments .put (fieldMapping , rowExpression );
278+ newMappings .add (fieldMapping );
277279 }
278280
279- return new RelationPlan (planBuilder .getRoot (), plan .getScope (), mappings );
281+ planBuilder = planBuilder .withNewRoot (new ProjectNode (
282+ idAllocator .getNextId (),
283+ planBuilder .getRoot (),
284+ assignments .build ()));
285+
286+ return new RelationPlan (planBuilder .getRoot (), plan .getScope (), newMappings .build ());
280287 }
281288
282289 @ Override
0 commit comments