1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column;
19
20 import lombok.Getter;
21 import lombok.Setter;
22 import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
23 import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.ParenthesesSegment;
24 import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerAvailable;
25 import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerSegment;
26 import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.bounded.ColumnSegmentBoundedInfo;
27 import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
28
29 import java.util.LinkedList;
30 import java.util.List;
31 import java.util.Optional;
32 import java.util.stream.Collectors;
33
34
35
36
37 @Getter
38 @Setter
39 public final class ColumnSegment implements ExpressionSegment, OwnerAvailable {
40
41 private final int startIndex;
42
43 private final int stopIndex;
44
45 private final IdentifierValue identifier;
46
47 private List<IdentifierValue> nestedObjectAttributes;
48
49 private OwnerSegment owner;
50
51 private ColumnSegmentBoundedInfo columnBoundedInfo;
52
53 private ColumnSegmentBoundedInfo otherUsingColumnBoundedInfo;
54
55 private boolean isVariable;
56
57 private List<ParenthesesSegment> parentheses = new LinkedList<>();
58
59 public ColumnSegment(final int startIndex, final int stopIndex, final IdentifierValue identifier) {
60 this.startIndex = startIndex;
61 this.stopIndex = stopIndex;
62 this.identifier = identifier;
63 columnBoundedInfo = new ColumnSegmentBoundedInfo(identifier);
64 }
65
66
67
68
69
70
71
72 public String getQualifiedName() {
73 String column = identifier.getValueWithQuoteCharacters();
74 if (null != nestedObjectAttributes && !nestedObjectAttributes.isEmpty()) {
75 column = String.join(".", column, nestedObjectAttributes.stream().map(IdentifierValue::getValueWithQuoteCharacters).collect(Collectors.joining(".")));
76 }
77 return null == owner ? column : String.join(".", owner.getIdentifier().getValueWithQuoteCharacters(), column);
78 }
79
80
81
82
83
84
85 public String getExpression() {
86 String column = identifier.getValue();
87 if (null != nestedObjectAttributes && !nestedObjectAttributes.isEmpty()) {
88 column = String.join(".", column, nestedObjectAttributes.stream().map(IdentifierValue::getValue).collect(Collectors.joining(".")));
89 }
90 return null == owner ? column : String.join(".", owner.getIdentifier().getValue(), column);
91 }
92
93 @Override
94 public Optional<OwnerSegment> getOwner() {
95 return Optional.ofNullable(owner);
96 }
97
98 @Override
99 public String getText() {
100 return getExpression();
101 }
102 }