Skip to content

Commit f99f1e3

Browse files
authored
Merge pull request #374 from alex268/table_type_support
Added support of StoreType and not null columns
2 parents 446bd2d + a80c8a6 commit f99f1e3

File tree

5 files changed

+49
-5
lines changed

5 files changed

+49
-5
lines changed

table/pom.xml

-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
<plugin>
4848
<groupId>org.apache.maven.plugins</groupId>
4949
<artifactId>maven-surefire-plugin</artifactId>
50-
<version>3.1.0</version>
5150
<configuration>
5251
<environmentVariables>
5352
<TESTCONTAINERS_REUSE_ENABLE>true</TESTCONTAINERS_REUSE_ENABLE>

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

+16-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@
2424
* @author Sergey Polovko
2525
*/
2626
public class TableDescription {
27+
public enum StoreType {
28+
ROW,
29+
COLUMN
30+
}
2731

32+
private final StoreType storeType;
2833
private final List<String> primaryKeys;
2934
private final List<TableColumn> columns;
3035
private final List<TableIndex> indexes;
@@ -42,6 +47,7 @@ public class TableDescription {
4247
private final TableTtl tableTtl;
4348

4449
private TableDescription(Builder builder) {
50+
this.storeType = builder.storeType;
4551
this.primaryKeys = ImmutableList.copyOf(builder.primaryKeys);
4652
this.columns = builder.buildColumns();
4753
this.indexes = ImmutableList.copyOf(builder.indexes);
@@ -59,6 +65,10 @@ public static Builder newBuilder() {
5965
return new Builder();
6066
}
6167

68+
public StoreType getStoreType() {
69+
return storeType;
70+
}
71+
6272
public List<String> getPrimaryKeys() {
6373
return primaryKeys;
6474
}
@@ -105,7 +115,7 @@ public List<ChangefeedDescription> getChangefeeds() {
105115
* BUILDER
106116
*/
107117
public static class Builder {
108-
118+
private StoreType storeType = StoreType.ROW;
109119
private List<String> primaryKeys = Collections.emptyList();
110120
private final LinkedHashMap<String, TypeAndFamily> columns = new LinkedHashMap<>();
111121
private final List<TableIndex> indexes = new ArrayList<>();
@@ -118,6 +128,11 @@ public static class Builder {
118128
private TableTtl ttlSettings = TableTtl.notSet();
119129
private final List<ChangefeedDescription> changefeeds = new ArrayList<>();
120130

131+
public Builder setStoreType(StoreType storeType) {
132+
this.storeType = storeType;
133+
return this;
134+
}
135+
121136
public Builder addNonnullColumn(String name, Type type) {
122137
return addNonnullColumn(name, type, null);
123138
}

table/src/main/java/tech/ydb/table/impl/BaseSession.java

+28
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
import tech.ydb.table.values.ListValue;
9292
import tech.ydb.table.values.StructValue;
9393
import tech.ydb.table.values.TupleValue;
94+
import tech.ydb.table.values.Type;
9495
import tech.ydb.table.values.Value;
9596
import tech.ydb.table.values.proto.ProtoType;
9697
import tech.ydb.table.values.proto.ProtoValue;
@@ -208,6 +209,9 @@ private static YdbTable.ColumnMeta buildColumnMeta(TableColumn column) {
208209
if (column.getFamily() != null) {
209210
builder.setFamily(column.getFamily());
210211
}
212+
if (column.getType().getKind() != Type.Kind.OPTIONAL) {
213+
builder.setNotNull(true);
214+
}
211215
return builder.build();
212216
}
213217

@@ -362,6 +366,17 @@ public CompletableFuture<Status> createTable(
362366
.setOperationParams(Operation.buildParams(settings.toOperationSettings()))
363367
.addAllPrimaryKey(description.getPrimaryKeys());
364368

369+
switch (description.getStoreType()) {
370+
case ROW:
371+
request.setStoreType(YdbTable.StoreType.STORE_TYPE_ROW);
372+
break;
373+
case COLUMN:
374+
request.setStoreType(YdbTable.StoreType.STORE_TYPE_COLUMN);
375+
break;
376+
default:
377+
break;
378+
}
379+
365380
for (ColumnFamily family: description.getColumnFamilies()) {
366381
request.addColumnFamilies(buildColumnFamity(family));
367382
}
@@ -726,6 +741,19 @@ private static TableDescription mapDescribeTable(
726741
DescribeTableSettings describeTableSettings
727742
) {
728743
TableDescription.Builder description = TableDescription.newBuilder();
744+
switch (result.getStoreType()) {
745+
case STORE_TYPE_ROW:
746+
description = description.setStoreType(TableDescription.StoreType.ROW);
747+
break;
748+
case STORE_TYPE_COLUMN:
749+
description = description.setStoreType(TableDescription.StoreType.COLUMN);
750+
break;
751+
case UNRECOGNIZED:
752+
case STORE_TYPE_UNSPECIFIED:
753+
default:
754+
break;
755+
}
756+
729757
for (int i = 0; i < result.getColumnsCount(); i++) {
730758
YdbTable.ColumnMeta column = result.getColumns(i);
731759
description.addNonnullColumn(column.getName(), ProtoType.fromPb(column.getType()), column.getFamily());

table/src/test/java/tech/ydb/table/integration/AlterTableTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public void alterTableTest() {
7474

7575
TableDescription description = describeResult.getValue();
7676

77+
Assert.assertEquals(TableDescription.StoreType.ROW, description.getStoreType());
7778
Assert.assertEquals(1, description.getColumnFamilies().size());
7879
Assert.assertEquals(DEFAULT_FAMILY, description.getColumnFamilies().get(0).getName());
7980

table/src/test/java/tech/ydb/table/integration/RenameTablesTest.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package tech.ydb.table.integration;
22

33
import java.util.Arrays;
4+
45
import org.junit.Assert;
56
import org.junit.ClassRule;
67
import org.junit.Test;
8+
79
import tech.ydb.core.Result;
810
import tech.ydb.core.Status;
9-
1011
import tech.ydb.table.SessionRetryContext;
1112
import tech.ydb.table.description.TableColumn;
1213
import tech.ydb.table.description.TableDescription;
@@ -53,8 +54,8 @@ public class RenameTablesTest {
5354
public void testRenameTables() {
5455
TableDescription tableDescription = TableDescription.newBuilder()
5556
.addNullableColumn("id", PrimitiveType.Uint64)
56-
.addNullableColumn("code", PrimitiveType.Text)
57-
.addNullableColumn("size", PrimitiveType.Float)
57+
.addNonnullColumn("code", PrimitiveType.Text)
58+
.addNonnullColumn("size", PrimitiveType.Float)
5859
.addNullableColumn("created", PrimitiveType.Timestamp)
5960
.addNullableColumn("data", PrimitiveType.Json)
6061
.setPrimaryKey("id")

0 commit comments

Comments
 (0)