Skip to content

Commit

Permalink
Added NullType support
Browse files Browse the repository at this point in the history
  • Loading branch information
alex268 committed Jul 5, 2024
1 parent 10c77c4 commit 39908bf
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ static AbstractValueReader forTypeImpl(ValueProtos.Type type) {
case VARIANT_TYPE:
return variantReader(type);
case VOID_TYPE:
case NULL_TYPE:
return ProtoVoidValueReader.INSTANCE;
default:
throw new IllegalStateException("unsupported type: " + type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ public static Type fromPb(ValueProtos.Type type) {
}

case VOID_TYPE:
case NULL_TYPE:
return VoidType.of();

case PG_TYPE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import com.google.common.collect.Maps;
import com.google.protobuf.ByteString;
import com.google.protobuf.NullValue;
import com.google.protobuf.UnsafeByteOperations;

import tech.ydb.proto.ValueProtos;
Expand Down Expand Up @@ -50,11 +49,11 @@ public class ProtoValue {
private static final ValueProtos.Value EMPTY = ValueProtos.Value.newBuilder().build();

private static final ValueProtos.Value EMPTY_OPTIONAL = ValueProtos.Value.newBuilder()
.setNullFlagValue(NullValue.NULL_VALUE)
.setNullFlagValue(com.google.protobuf.NullValue.NULL_VALUE)
.build();

private static final ValueProtos.Value VOID = ValueProtos.Value.newBuilder()
.setNullFlagValue(NullValue.NULL_VALUE)
.setNullFlagValue(com.google.protobuf.NullValue.NULL_VALUE)
.build();

private ProtoValue() { }
Expand Down
57 changes: 57 additions & 0 deletions table/src/test/java/tech/ydb/table/integration/NullReadTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package tech.ydb.table.integration;

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

import tech.ydb.table.SessionRetryContext;
import tech.ydb.table.impl.SimpleTableClient;
import tech.ydb.table.query.DataQueryResult;
import tech.ydb.table.result.ResultSetReader;
import tech.ydb.table.result.ValueReader;
import tech.ydb.table.rpc.grpc.GrpcTableRpc;
import tech.ydb.table.transaction.TxControl;
import tech.ydb.table.values.PrimitiveType;
import tech.ydb.table.values.VoidType;
import tech.ydb.table.values.VoidValue;
import tech.ydb.test.junit4.GrpcTransportRule;

/**
*
* @author Aleksandr Gorshenin
*/
public class NullReadTest {
@ClassRule
public static final GrpcTransportRule YDB_TRANSPORT = new GrpcTransportRule();
private static final SessionRetryContext CTX = SessionRetryContext.create(SimpleTableClient.newClient(
GrpcTableRpc.useTransport(YDB_TRANSPORT)
).build()).build();

@Test
public void nullReadTest() {
DataQueryResult result = CTX.supplyResult(
s -> s.executeDataQuery("SELECT '1' AS p1, 123 AS p2, NULL AS p3", TxControl.serializableRw())
).join().getValue();

Assert.assertEquals(1, result.getResultSetCount());

ResultSetReader rs = result.getResultSet(0);
Assert.assertTrue(rs.next());

ValueReader p1 = rs.getColumn("p1");
ValueReader p2 = rs.getColumn("p2");
ValueReader p3 = rs.getColumn("p3");

Assert.assertNotNull(p1);
Assert.assertNotNull(p2);
Assert.assertNotNull(p3);

Assert.assertEquals(PrimitiveType.Bytes, p1.getType());
Assert.assertEquals(PrimitiveType.Int32, p2.getType());
Assert.assertEquals(VoidType.of(), p3.getType());

Assert.assertArrayEquals(new byte[] { '1' }, p1.getBytes());
Assert.assertEquals(123, p2.getInt32());
Assert.assertEquals(VoidValue.of(), p3.getValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@

import javax.annotation.Nonnull;

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

import tech.ydb.core.StatusCode;
import tech.ydb.core.UnexpectedResultException;
import tech.ydb.table.SessionRetryContext;
import tech.ydb.table.description.TableDescription;
import tech.ydb.table.impl.SimpleTableClient;
Expand All @@ -21,11 +25,6 @@
import tech.ydb.table.values.StructValue;
import tech.ydb.test.junit4.GrpcTransportRule;

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


public class TableQueryTest {
@ClassRule
Expand Down Expand Up @@ -172,11 +171,11 @@ public void testReadRowsEmptyColumns() {
).join().getValue().getResultSetReader();

Assert.assertTrue(rsr.next());
Assert.assertEquals(rsr.getColumn("series_id").getUint64(), 1);
Assert.assertEquals(1, rsr.getColumn("series_id").getUint64());
Assert.assertEquals("Once I rose above the noise and confusion", rsr.getColumn("title").getText());
Assert.assertEquals("Carry on my wayward son", rsr.getColumn("series_info").getText());
Assert.assertTrue(rsr.next());
Assert.assertEquals(rsr.getColumn("series_id").getUint64(), 2);
Assert.assertEquals(2, rsr.getColumn("series_id").getUint64());
Assert.assertEquals("There'll be peace when you are done", rsr.getColumn("title").getText());
Assert.assertEquals("Lay your weary head to rest", rsr.getColumn("series_info").getText());
Assert.assertFalse(rsr.next());
Expand Down

0 comments on commit 39908bf

Please sign in to comment.