@Override public NameSegment cloneWithNewChild(PathSegment newChild) { NameSegment s = new NameSegment(this.path); if (getChild() != null) { s.setChild(getChild().cloneWithNewChild(newChild)); } else { s.setChild(newChild); } return s; } }
@Override public ArraySegment cloneWithNewChild(PathSegment newChild) { ArraySegment seg = index < 0 ? new ArraySegment((PathSegment) null) : new ArraySegment(index); if (getChild() != null) { seg.setChild(getChild().cloneWithNewChild(newChild)); } else { seg.setChild(newChild); } return seg; } }
@Test public void testIfMultiLevelCloneWorks() { final int levels = 10; final PathSegment segment = new PathSegment.NameSegment("test", makeArraySegment(levels, null)); final PathSegment clone = segment.clone(); assertEquals("result of clone & original segments must be identical", segment, clone); final PathSegment tail = new PathSegment.NameSegment("tail"); final PathSegment newSegment = new PathSegment.NameSegment("test", makeArraySegment(levels, tail)); final PathSegment newClone = segment.cloneWithNewChild(tail); assertEquals("result of cloneWithChild & original segment must be identical", newSegment, newClone); } }
@Override public PathSegment visitCall(RexCall call) { if ("ITEM".equals(call.getOperator().getName())) { stackDepth++; PathSegment mapOrArray = call.operands.get(0).accept(this); stackDepth--; if (mapOrArray != null) { if (call.operands.get(1) instanceof RexLiteral) { PathSegment newFieldPath = newPath( mapOrArray.cloneWithNewChild(convertLiteral((RexLiteral) call.operands.get(1))), call); return newFieldPath; } return mapOrArray; } } else { for (RexNode operand : call.operands) { operand.accept(this); } } return null; } }
@Override public NameSegment cloneWithNewChild(PathSegment newChild) { NameSegment s = new NameSegment(this.path); if (getChild() != null) { s.setChild(getChild().cloneWithNewChild(newChild)); } else { s.setChild(newChild); } return s; } }
@Override public ArraySegment cloneWithNewChild(PathSegment newChild) { ArraySegment seg = index < 0 ? new ArraySegment((PathSegment) null) : new ArraySegment(index); if (getChild() != null) { seg.setChild(getChild().cloneWithNewChild(newChild)); } else { seg.setChild(newChild); } return seg; } }
@Override public PathSegment visitCall(RexCall call) { String itemStarFieldName = FieldsReWriterUtil.getFieldNameFromItemStarField(call, fieldNames); if (itemStarFieldName != null) { addDesiredField(itemStarFieldName, call.getType(), call); return new PathSegment.NameSegment(itemStarFieldName); } if (SqlStdOperatorTable.ITEM.equals(call.getOperator())) { PathSegment mapOrArray = call.operands.get(0).accept(this); if (mapOrArray != null) { if (call.operands.get(1) instanceof RexLiteral) { return mapOrArray.cloneWithNewChild(Utilities.convertLiteral((RexLiteral) call.operands.get(1))); } return mapOrArray; } } else { for (RexNode operand : call.operands) { addField(operand.accept(this)); } } return null; }