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.item;
19
20 import lombok.Getter;
21 import lombok.RequiredArgsConstructor;
22 import lombok.Setter;
23 import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.AliasAvailable;
24 import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.AliasSegment;
25 import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerAvailable;
26 import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerSegment;
27 import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
28
29 import java.util.Collection;
30 import java.util.LinkedList;
31 import java.util.Optional;
32
33
34
35
36 @RequiredArgsConstructor
37 @Getter
38 @Setter
39 public final class ShorthandProjectionSegment implements ProjectionSegment, OwnerAvailable, AliasAvailable {
40
41 private final int startIndex;
42
43 private final int stopIndex;
44
45 private OwnerSegment owner;
46
47 private AliasSegment alias;
48
49 private Collection<ProjectionSegment> actualProjectionSegments = new LinkedList<>();
50
51 @Override
52 public String getColumnLabel() {
53 return getAliasName().orElse("*");
54 }
55
56 @Override
57 public Optional<OwnerSegment> getOwner() {
58 return Optional.ofNullable(owner);
59 }
60
61 @Override
62 public Optional<String> getAliasName() {
63 return null == alias ? Optional.empty() : Optional.ofNullable(alias.getIdentifier().getValue());
64 }
65
66 @Override
67 public Optional<IdentifierValue> getAlias() {
68 return Optional.ofNullable(alias).map(AliasSegment::getIdentifier);
69 }
70
71
72
73
74
75
76 public Optional<AliasSegment> getAliasSegment() {
77 return Optional.ofNullable(alias);
78 }
79 }