Skip to content
Merged
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
* Query: Added support of ApacheArrow for query execution
* Tests: Updated testcontainers to 2.0.3

## 2.3.34 ##
* Table: Fixed StoragePool mapping for CreateTable
* Core: Added method to customize x-build-info

## 2.3.33 ##
* Topic: Fixed race between decoder and function that publishes messages to user

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,6 @@ public void testNoTxStatement() {
Assert.assertEquals(StatusCode.PRECONDITION_FAILED, result.getStatus().getCode());
Issue issue = Issue.of(2012,
"Constraint violated. Table: `" + ydbTransport.getDatabase() + "/" + TEST_TABLE + "`.",
// "Conflict with existing key.",
Issue.Severity.ERROR
);
Assert.assertArrayEquals(new Issue[] { issue }, result.getStatus().getIssues());
Expand Down
39 changes: 21 additions & 18 deletions table/src/main/java/tech/ydb/table/impl/BaseSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,23 +348,28 @@ private static YdbTable.TableIndex buildIndex(TableIndex index) {
}

private static YdbTable.ColumnFamily buildColumnFamily(ColumnFamily family) {
YdbTable.ColumnFamily.Compression compression;
switch (family.getCompression()) {
case COMPRESSION_NONE:
compression = YdbTable.ColumnFamily.Compression.COMPRESSION_NONE;
break;
case COMPRESSION_LZ4:
compression = YdbTable.ColumnFamily.Compression.COMPRESSION_LZ4;
break;
default:
compression = YdbTable.ColumnFamily.Compression.COMPRESSION_UNSPECIFIED;
YdbTable.ColumnFamily.Builder builder = YdbTable.ColumnFamily.newBuilder()
.setName(family.getName());
if (family.getCompression() != null) {
switch (family.getCompression()) {
case COMPRESSION_NONE:
builder = builder.setCompression(YdbTable.ColumnFamily.Compression.COMPRESSION_NONE);
break;
case COMPRESSION_LZ4:
builder = builder.setCompression(YdbTable.ColumnFamily.Compression.COMPRESSION_LZ4);
break;
default:
// Nothing
break;
}
}

return YdbTable.ColumnFamily.newBuilder()
.setCompression(compression)
.setData(YdbTable.StoragePool.newBuilder().setMedia(family.getData().getMedia()))
.setName(family.getName())
.build();
StoragePool data = family.getData();
if (data != null && data.getMedia() != null && !data.getMedia().isEmpty()) {
builder.setData(YdbTable.StoragePool.newBuilder().setMedia(data.getMedia()));
}

return builder.build();
}

private static YdbTable.TtlSettings buildTtlSettings(TableTtl ttl) {
Expand Down Expand Up @@ -441,9 +446,7 @@ public CompletableFuture<Status> createTable(
}

for (ColumnFamily family : description.getColumnFamilies()) {
if (!"default".equals(family.getName())) {
request.addColumnFamilies(buildColumnFamily(family));
}
request.addColumnFamilies(buildColumnFamily(family));
}

for (TableColumn column : description.getColumns()) {
Expand Down
31 changes: 31 additions & 0 deletions table/src/test/java/tech/ydb/table/impl/BaseSessionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package tech.ydb.table.impl;

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

import tech.ydb.table.description.ColumnFamily;

/**
*
* @author Aleksandr Gorshenin {@literal <alexandr268@ydb.tech>}
*/
public class BaseSessionTest {

/**
* Verifies that the {@link ColumnFamily.Compression} enum declares exactly the expected constants:
* {@code COMPRESSION_NONE} and {@code COMPRESSION_LZ4}.
* <p>
* This check matters because the values are used when mapping to and from the protobuf representation. Any change
* to the enum would break this test and signals that
* {@link BaseSession#buildColumnFamily(tech.ydb.table.description.ColumnFamily)} and
* {@link BaseSession#mapDescribeTable(tech.ydb.core.Result, tech.ydb.table.settings.DescribeTableSettings)}
* need to be updated as well.
*/
@Test
public void columnFamilyTest() {
Assert.assertArrayEquals(new ColumnFamily.Compression[] {
ColumnFamily.Compression.COMPRESSION_NONE,
ColumnFamily.Compression.COMPRESSION_LZ4
}, ColumnFamily.Compression.values());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,4 @@ private void futureHasException(CompletableFuture<?> future, String message) {
Assert.assertNotNull("Test interrupted", ex);
}
}


}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tech.ydb.table.integration;

import org.junit.After;
import org.junit.Assert;
import org.junit.ClassRule;
import org.junit.Test;
Expand All @@ -8,21 +9,38 @@
import tech.ydb.core.Status;
import tech.ydb.core.StatusCode;
import tech.ydb.table.SessionRetryContext;
import tech.ydb.table.description.ColumnFamily;
import tech.ydb.table.description.TableDescription;
import tech.ydb.table.impl.SimpleTableClient;
import tech.ydb.table.rpc.grpc.GrpcTableRpc;
import tech.ydb.table.values.PrimitiveType;
import tech.ydb.table.values.PrimitiveValue;
import tech.ydb.test.junit4.GrpcTransportRule;

/**
*
* @author Aleksandr Gorshenin
*/
public class DescribeTableTest {
private static final String TABLE_NAME = "table_describe_test";
private static final String TABLE_COPY_NAME = "table_describe_test_copy";

@ClassRule
public static final GrpcTransportRule YDB_TRANSPORT = new GrpcTransportRule();

private static final SessionRetryContext CTX = SessionRetryContext.create(SimpleTableClient.newClient(
GrpcTableRpc.useTransport(YDB_TRANSPORT)
).build()).build();

private final String tablePath = YDB_TRANSPORT.getDatabase() + "/" + TABLE_NAME;
private final String tableCopyPath = YDB_TRANSPORT.getDatabase() + "/" + TABLE_COPY_NAME;

@After
public void dropTable() {
CTX.supplyStatus(session -> session.dropTable(tablePath)).join();
CTX.supplyStatus(session -> session.dropTable(tableCopyPath)).join();
}

@Test
public void wrongTypeTest() {
String databasePath = YDB_TRANSPORT.getDatabase();
Expand All @@ -36,4 +54,42 @@ public void wrongTypeTest() {
Assert.assertEquals("Entry " + entryName + " with type DIRECTORY is not a table", issues[0].getMessage());
Assert.assertEquals(Issue.Severity.ERROR, issues[0].getSeverity());
}

@Test
public void copyTableTest() {
TableDescription createTable = TableDescription.newBuilder()
.addNonnullColumn("id", PrimitiveType.Int8)
.addNonnullColumn("version", PrimitiveType.Uint32)
.addNullableColumn("value", PrimitiveType.Text, PrimitiveValue.newText("123"))
.addColumnFamily(new ColumnFamily("default", null, ColumnFamily.Compression.COMPRESSION_LZ4))
.addColumnFamily(new ColumnFamily("raw", null, null))
.setPrimaryKeys("id", "version")
.build();

CTX.supplyStatus(session -> session.createTable(tablePath, createTable)).join()
.expectSuccess("cannot create table " + tablePath);

TableDescription tableDesc = CTX.supplyResult(session -> session.describeTable(tablePath)).join().getValue();

Assert.assertEquals(2, tableDesc.getColumnFamilies().size());
Assert.assertEquals(ColumnFamily.Compression.COMPRESSION_LZ4, findFamily(tableDesc, "default").getCompression());
Assert.assertEquals(ColumnFamily.Compression.COMPRESSION_NONE, findFamily(tableDesc, "raw").getCompression());

CTX.supplyStatus(session -> session.createTable(tableCopyPath, tableDesc)).join()
.expectSuccess("cannot create table " + tableCopyPath);

TableDescription copyDesc = CTX.supplyResult(session -> session.describeTable(tableCopyPath)).join().getValue();
Assert.assertEquals(2, copyDesc.getColumnFamilies().size());
Assert.assertEquals(ColumnFamily.Compression.COMPRESSION_LZ4, findFamily(copyDesc, "default").getCompression());
Assert.assertEquals(ColumnFamily.Compression.COMPRESSION_NONE, findFamily(copyDesc, "raw").getCompression());
}

private ColumnFamily findFamily(TableDescription desc, String name) {
for (ColumnFamily family : desc.getColumnFamilies()) {
if (name.equals(family.getName())) {
return family;
}
}
throw new AssertionError("Expected column family with name " + name);
}
}