Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion table/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<environmentVariables>
<TESTCONTAINERS_REUSE_ENABLE>true</TESTCONTAINERS_REUSE_ENABLE>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@
* @author Sergey Polovko
*/
public class TableDescription {
public enum StoreType {
ROWS,
COLUMNS
}

private final StoreType storeType;
private final List<String> primaryKeys;
private final List<TableColumn> columns;
private final List<TableIndex> indexes;
Expand All @@ -42,6 +47,7 @@ public class TableDescription {
private final TableTtl tableTtl;

private TableDescription(Builder builder) {
this.storeType = builder.storeType;
this.primaryKeys = ImmutableList.copyOf(builder.primaryKeys);
this.columns = builder.buildColumns();
this.indexes = ImmutableList.copyOf(builder.indexes);
Expand All @@ -59,6 +65,10 @@ public static Builder newBuilder() {
return new Builder();
}

public StoreType getStoreType() {
return storeType;
}

public List<String> getPrimaryKeys() {
return primaryKeys;
}
Expand Down Expand Up @@ -105,7 +115,7 @@ public List<ChangefeedDescription> getChangefeeds() {
* BUILDER
*/
public static class Builder {

private StoreType storeType = StoreType.ROWS;
private List<String> primaryKeys = Collections.emptyList();
private final LinkedHashMap<String, TypeAndFamily> columns = new LinkedHashMap<>();
private final List<TableIndex> indexes = new ArrayList<>();
Expand All @@ -118,6 +128,11 @@ public static class Builder {
private TableTtl ttlSettings = TableTtl.notSet();
private final List<ChangefeedDescription> changefeeds = new ArrayList<>();

public Builder setStoreType(StoreType storeType) {
this.storeType = storeType;
return this;
}

public Builder addNonnullColumn(String name, Type type) {
return addNonnullColumn(name, type, null);
}
Expand Down
28 changes: 28 additions & 0 deletions table/src/main/java/tech/ydb/table/impl/BaseSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
import tech.ydb.table.values.ListValue;
import tech.ydb.table.values.StructValue;
import tech.ydb.table.values.TupleValue;
import tech.ydb.table.values.Type;
import tech.ydb.table.values.Value;
import tech.ydb.table.values.proto.ProtoType;
import tech.ydb.table.values.proto.ProtoValue;
Expand Down Expand Up @@ -208,6 +209,9 @@ private static YdbTable.ColumnMeta buildColumnMeta(TableColumn column) {
if (column.getFamily() != null) {
builder.setFamily(column.getFamily());
}
if (column.getType().getKind() != Type.Kind.OPTIONAL) {
builder.setNotNull(true);
}
return builder.build();
}

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

switch (description.getStoreType()) {
case ROWS:
request.setStoreType(YdbTable.StoreType.STORE_TYPE_ROW);
break;
case COLUMNS:
request.setStoreType(YdbTable.StoreType.STORE_TYPE_COLUMN);
break;
default:
break;
}

for (ColumnFamily family: description.getColumnFamilies()) {
request.addColumnFamilies(buildColumnFamity(family));
}
Expand Down Expand Up @@ -726,6 +741,19 @@ private static TableDescription mapDescribeTable(
DescribeTableSettings describeTableSettings
) {
TableDescription.Builder description = TableDescription.newBuilder();
switch (result.getStoreType()) {
case STORE_TYPE_ROW:
description = description.setStoreType(TableDescription.StoreType.ROWS);
break;
case STORE_TYPE_COLUMN:
description = description.setStoreType(TableDescription.StoreType.COLUMNS);
break;
case UNRECOGNIZED:
case STORE_TYPE_UNSPECIFIED:
default:
break;
}

for (int i = 0; i < result.getColumnsCount(); i++) {
YdbTable.ColumnMeta column = result.getColumns(i);
description.addNonnullColumn(column.getName(), ProtoType.fromPb(column.getType()), column.getFamily());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public void alterTableTest() {

TableDescription description = describeResult.getValue();

Assert.assertEquals(TableDescription.StoreType.ROWS, description.getStoreType());
Assert.assertEquals(1, description.getColumnFamilies().size());
Assert.assertEquals(DEFAULT_FAMILY, description.getColumnFamilies().get(0).getName());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package tech.ydb.table.integration;

import java.util.Arrays;

import org.junit.Assert;
import org.junit.ClassRule;
import org.junit.Test;

import tech.ydb.core.Result;
import tech.ydb.core.Status;

import tech.ydb.table.SessionRetryContext;
import tech.ydb.table.description.TableColumn;
import tech.ydb.table.description.TableDescription;
Expand Down Expand Up @@ -53,8 +54,8 @@ public class RenameTablesTest {
public void testRenameTables() {
TableDescription tableDescription = TableDescription.newBuilder()
.addNullableColumn("id", PrimitiveType.Uint64)
.addNullableColumn("code", PrimitiveType.Text)
.addNullableColumn("size", PrimitiveType.Float)
.addNonnullColumn("code", PrimitiveType.Text)
.addNonnullColumn("size", PrimitiveType.Float)
.addNullableColumn("created", PrimitiveType.Timestamp)
.addNullableColumn("data", PrimitiveType.Json)
.setPrimaryKey("id")
Expand Down
Loading