1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.shardingsphere.infra.binder.context.segment.select.projection.impl;
19
20 import lombok.EqualsAndHashCode;
21 import lombok.Getter;
22 import lombok.RequiredArgsConstructor;
23 import lombok.ToString;
24 import org.apache.shardingsphere.infra.binder.context.segment.select.projection.Projection;
25 import org.apache.shardingsphere.infra.binder.context.segment.select.projection.util.ProjectionUtils;
26 import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
27 import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.SubqueryProjectionSegment;
28 import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
29
30 import java.util.Optional;
31
32
33
34
35 @RequiredArgsConstructor
36 @Getter
37 @EqualsAndHashCode
38 @ToString
39 public final class SubqueryProjection implements Projection {
40
41 private final SubqueryProjectionSegment subquerySegment;
42
43 private final Projection projection;
44
45 private final IdentifierValue alias;
46
47 private final DatabaseType databaseType;
48
49 @Override
50 public String getColumnName() {
51 return getColumnLabel();
52 }
53
54 @Override
55 public String getColumnLabel() {
56 return getAlias().isPresent() ? ProjectionUtils.getColumnLabelFromAlias(getAlias().get(), databaseType) : ProjectionUtils.getColumnNameFromSubquery(subquerySegment, databaseType);
57 }
58
59 @Override
60 public Optional<IdentifierValue> getAlias() {
61 return Optional.ofNullable(alias);
62 }
63
64 @Override
65 public String getExpression() {
66 return subquerySegment.getText();
67 }
68 }