Skip to content

Commit 0fadff6

Browse files
feat(TableService): CreateTable with default value options
1 parent 8dfe1d1 commit 0fadff6

File tree

4 files changed

+320
-32
lines changed

4 files changed

+320
-32
lines changed

table/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
<environmentVariables>
5252
<TESTCONTAINERS_REUSE_ENABLE>true</TESTCONTAINERS_REUSE_ENABLE>
5353
<YDB_DOCKER_IMAGE>ydbplatform/local-ydb:trunk</YDB_DOCKER_IMAGE>
54-
<YDB_FEATURE_FLAGS>enable_vector_index</YDB_FEATURE_FLAGS>
5554
</environmentVariables>
5655
</configuration>
5756
</plugin>
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
package tech.ydb.table.description;
2+
3+
import javax.annotation.Nullable;
4+
5+
/**
6+
* @author Kirill Kurdyukov
7+
*/
8+
public class SequenceDescription {
9+
10+
public String getName() {
11+
return name;
12+
}
13+
14+
@Nullable
15+
public Long getMinValue() {
16+
return minValue;
17+
}
18+
19+
@Nullable
20+
public Long getMaxValue() {
21+
return maxValue;
22+
}
23+
24+
@Nullable
25+
public Long getStartValue() {
26+
return startValue;
27+
}
28+
29+
@Nullable
30+
public Long getCache() {
31+
return cache;
32+
}
33+
34+
@Nullable
35+
public Long getIncrement() {
36+
return increment;
37+
}
38+
39+
@Nullable
40+
public Boolean getCycle() {
41+
return cycle;
42+
}
43+
44+
@Nullable
45+
public SetVal getSetVal() {
46+
return setVal;
47+
}
48+
49+
public static class SetVal {
50+
@Nullable
51+
private final Long nextValue;
52+
@Nullable
53+
private final Boolean nextUsed;
54+
55+
public SetVal(@Nullable Long nextValue, @Nullable Boolean nextUsed) {
56+
this.nextValue = nextValue;
57+
this.nextUsed = nextUsed;
58+
}
59+
60+
@Nullable
61+
public Long getNextValue() {
62+
return nextValue;
63+
}
64+
65+
@Nullable
66+
public Boolean getNextUsed() {
67+
return nextUsed;
68+
}
69+
}
70+
71+
private final String name;
72+
@Nullable
73+
private final Long minValue;
74+
@Nullable
75+
private final Long maxValue;
76+
@Nullable
77+
private final Long startValue;
78+
@Nullable
79+
private final Long cache;
80+
@Nullable
81+
private final Long increment;
82+
@Nullable
83+
private final Boolean cycle;
84+
@Nullable
85+
private final SetVal setVal;
86+
87+
private SequenceDescription(Builder builder) {
88+
this.name = builder.name;
89+
this.minValue = builder.minValue;
90+
this.maxValue = builder.maxValue;
91+
this.startValue = builder.startValue;
92+
this.cache = builder.cache;
93+
this.increment = builder.increment;
94+
this.cycle = builder.cycle;
95+
this.setVal = builder.setVal;
96+
}
97+
98+
public static Builder newBuilder() {
99+
return new Builder();
100+
}
101+
102+
public static class Builder {
103+
private String name;
104+
private Long minValue;
105+
private Long maxValue;
106+
private Long startValue;
107+
private Long cache;
108+
private Long increment;
109+
private Boolean cycle;
110+
private SetVal setVal;
111+
112+
public Builder setName(String name) {
113+
this.name = name;
114+
return this;
115+
}
116+
117+
public Builder setMinValue(@Nullable Long minValue) {
118+
this.minValue = minValue;
119+
return this;
120+
}
121+
122+
public Builder setMaxValue(@Nullable Long maxValue) {
123+
this.maxValue = maxValue;
124+
return this;
125+
}
126+
127+
public Builder setStartValue(@Nullable Long startValue) {
128+
this.startValue = startValue;
129+
return this;
130+
}
131+
132+
public Builder setCache(@Nullable Long cache) {
133+
this.cache = cache;
134+
return this;
135+
}
136+
137+
public Builder setIncrement(@Nullable Long increment) {
138+
this.increment = increment;
139+
return this;
140+
}
141+
142+
public Builder setCycle(@Nullable Boolean cycle) {
143+
this.cycle = cycle;
144+
return this;
145+
}
146+
147+
public Builder setSetVal(@Nullable Long nextValue, @Nullable Boolean nextUsed) {
148+
this.setVal = new SetVal(nextValue, nextUsed);
149+
return this;
150+
}
151+
152+
public SequenceDescription build() {
153+
if (name == null) {
154+
throw new IllegalStateException("name is required");
155+
}
156+
157+
return new SequenceDescription(this);
158+
}
159+
}
160+
}

table/src/main/java/tech/ydb/table/description/TableColumn.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import javax.annotation.Nullable;
44

5+
import tech.ydb.table.values.PrimitiveValue;
56
import tech.ydb.table.values.Type;
67

78

@@ -14,14 +15,37 @@ public class TableColumn {
1415
private final Type type;
1516
@Nullable
1617
private final String family;
17-
1818
private final boolean hasDefaultValue;
19+
@Nullable
20+
private final PrimitiveValue literalDefaultValue;
21+
@Nullable
22+
private final SequenceDescription sequenceDescription;
1923

2024
public TableColumn(String name, Type type, String family, boolean hasDefaultValue) {
2125
this.name = name;
2226
this.type = type;
2327
this.family = family;
2428
this.hasDefaultValue = hasDefaultValue;
29+
this.literalDefaultValue = null;
30+
this.sequenceDescription = null;
31+
}
32+
33+
public TableColumn(String name, Type type, @Nullable String family, PrimitiveValue literalDefaultValue) {
34+
this.name = name;
35+
this.type = type;
36+
this.family = family;
37+
this.hasDefaultValue = true;
38+
this.literalDefaultValue = literalDefaultValue;
39+
this.sequenceDescription = null;
40+
}
41+
42+
public TableColumn(String name, Type type, @Nullable String family, SequenceDescription sequenceDescription) {
43+
this.name = name;
44+
this.type = type;
45+
this.family = family;
46+
this.hasDefaultValue = true;
47+
this.literalDefaultValue = null;
48+
this.sequenceDescription = sequenceDescription;
2549
}
2650

2751
public TableColumn(String name, Type type, String family) {
@@ -53,4 +77,14 @@ public String getFamily() {
5377
public String toString() {
5478
return name + ' ' + type;
5579
}
80+
81+
@Nullable
82+
public PrimitiveValue getLiteralDefaultValue() {
83+
return literalDefaultValue;
84+
}
85+
86+
@Nullable
87+
public SequenceDescription getSequenceDescription() {
88+
return sequenceDescription;
89+
}
5690
}

0 commit comments

Comments
 (0)