Progressed on port from dotnet to java

This commit is contained in:
David Noble
2019-09-08 20:37:12 -07:00
parent 7e30bf7456
commit ff8d32a8b5
60 changed files with 1659 additions and 1345 deletions

View File

@@ -19,7 +19,7 @@ public final class Out<T> {
private volatile T value;
public T get() {
return value;
return this.value;
}
public void set(T value) {
@@ -38,7 +38,7 @@ public final class Out<T> {
* @return {@code true} if there is a value present, otherwise {@code false}
*/
public boolean isPresent() {
return value != null;
return this.value != null;
}
/**
@@ -63,7 +63,7 @@ public final class Out<T> {
return false;
}
return Objects.equals(value, ((Out)other).value);
return Objects.equals(this.value, ((Out)other).value);
}
/**
@@ -74,11 +74,11 @@ public final class Out<T> {
*/
@Override
public int hashCode() {
return Objects.hashCode(value);
return Objects.hashCode(this.value);
}
@Override
public String toString() {
return value == null ? "null" : value.toString();
return this.value == null ? "null" : this.value.toString();
}
}

View File

@@ -115,7 +115,7 @@ public final class RowBuffer {
*/
public RowBuffer(final int capacity, @Nonnull final ByteBufAllocator allocator) {
checkArgument(capacity > 0, "capacity: %s", capacity);
checkNotNull(allocator, "allocator");
checkNotNull(allocator, "expected non-null allocator");
this.buffer = allocator.buffer(capacity);
this.resolver = null;
}
@@ -308,9 +308,9 @@ public final class RowBuffer {
*/
public void initLayout(HybridRowVersion version, Layout layout, LayoutResolver resolver) {
checkNotNull(version, "version");
checkNotNull(layout, "layout");
checkNotNull(resolver, "resolver");
checkNotNull(version, "expected non-null version");
checkNotNull(layout, "expected non-null layout");
checkNotNull(resolver, "expected non-null resolver");
this.writeHeader(new HybridRowHeader(version, layout.schemaId()));
this.buffer.writeZero(layout.size());
@@ -1336,7 +1336,7 @@ public final class RowBuffer {
@Nonnull final RowCursor edit, @Nonnull final LayoutScope scope, @Nonnull final UpdateOptions options) {
checkNotNull(edit, "expected non-null edit");
checkNotNull(scope, "expected non-null scopeType");
checkNotNull(scope, "expected non-null scope");
checkNotNull(options, "expected non-null options");
int length = LayoutCode.BYTES;
@@ -2185,11 +2185,10 @@ public final class RowBuffer {
checkState(this.length() == priorLength + shift.get());
}
public void writeVariableInt(int offset, long value, boolean exists, Out<Integer> shift) {
checkNotNull(shift, "expected non-null shift");
public int writeVariableInt(int offset, long value, boolean exists) {
final int length = RowBuffer.count7BitEncodedInt(value);
final Out<Integer> shift = new Out<>();
final Out<Integer> spaceNeeded = new Out<>();
final int priorLength = this.length();
@@ -2200,35 +2199,38 @@ public final class RowBuffer {
checkState(item.length == length);
checkState(spaceNeeded.get() == length);
checkState(this.length() == priorLength + shift.get());
return shift.get();
}
public void writeVariableString(
final int offset, @Nonnull final Utf8String value, final boolean exists, @Nonnull final Out<Integer> shift) {
public int writeVariableString(
final int offset, @Nonnull final Utf8String value, final boolean exists) {
checkNotNull(value, "expected non-null value");
checkNotNull(shift, "expected non-null shift");
checkArgument(!value.isNull(), "expected non-null value content");
checkArgument(offset >= 0, "expected non-negative offset, not %s", offset);
final int length = value.encodedLength();
final Out<Integer> shift = new Out<>();
final Out<Integer> spaceNeeded = new Out<>();
final int priorLength = this.length();
this.ensureVariable(offset, false, length, exists, spaceNeeded, shift);
Item<Utf8String> item = this.write(this::writeVariableString, offset, value);
checkState(spaceNeeded.get() == length + item.length());
checkState(this.length() == priorLength + shift.get());
return shift.get();
}
public void writeVariableUInt(
final int offset, final long value, final boolean exists, @Nonnull final Out<Integer> shift) {
public int writeVariableUInt(final int offset, final long value, final boolean exists) {
checkNotNull(shift, "expected non-null shift");
checkArgument(offset >= 0, "expected non-negative offset, not %s", offset);
final int length = RowBuffer.count7BitEncodedUInt(value);
final Out<Integer> shift = new Out<>();
final Out<Integer> spaceNeeded = new Out<>();
final int priorLength = this.length();
@@ -2239,6 +2241,8 @@ public final class RowBuffer {
checkState(item.length == length);
checkState(spaceNeeded.get() == length);
checkState(this.length() == priorLength + shift.get());
return shift.get();
}
/**
@@ -2505,7 +2509,7 @@ public final class RowBuffer {
) {
checkNotNull(edit, "expected non-null edit");
checkNotNull(type, "expected non-null cellType");
checkNotNull(type, "expected non-null type");
checkNotNull(typeArgs, "expected non-null typeArgs");
checkNotNull(options, "expected non-null options");
checkNotNull(metaBytes, "expected non-null metaBytes");

View File

@@ -81,7 +81,7 @@ public final class RowWriter {
//ORIGINAL LINE: return this.WritePrimitive(path, value, LayoutType.Binary, (ref RowWriter w, byte[] v) => w
// .row.WriteSparseBinary(ref w.cursor, v, UpdateOptions.Upsert));
return this.WritePrimitive(path, value, LayoutTypes.BINARY,
(ref RowWriter w, byte[] v) -> w.row.WriteSparseBinary(ref w.cursor, v, UpdateOptions.Upsert));
(ref RowWriter w, byte[] v) -> w.row.WriteSparseBinary(ref w.cursor, v, UpdateOptions.UPSERT));
}
/**
@@ -102,7 +102,7 @@ public final class RowWriter {
//ORIGINAL LINE: return this.WritePrimitive(path, value, LayoutType.Binary, (ref RowWriter w,
// ReadOnlySpan<byte> v) => w.row.WriteSparseBinary(ref w.cursor, v, UpdateOptions.Upsert));
return this.WritePrimitive(path, value, LayoutType.Binary,
(ref RowWriter w, ReadOnlySpan<Byte> v) -> w.row.WriteSparseBinary(ref w.cursor, v, UpdateOptions.Upsert));
(ref RowWriter w, ReadOnlySpan<Byte> v) -> w.row.WriteSparseBinary(ref w.cursor, v, UpdateOptions.UPSERT));
}
/**
@@ -124,7 +124,7 @@ public final class RowWriter {
// ReadOnlySequence<byte> v) => w.row.WriteSparseBinary(ref w.cursor, v, UpdateOptions.Upsert));
return this.WritePrimitive(path, value, LayoutType.Binary,
(ref RowWriter w, ReadOnlySequence<Byte> v) -> w.row.WriteSparseBinary(ref w.cursor, v,
UpdateOptions.Upsert));
UpdateOptions.UPSERT));
}
/**
@@ -140,7 +140,7 @@ public final class RowWriter {
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.WritePrimitive(path, value, LayoutType.Boolean,
(ref RowWriter w, boolean v) -> w.row.WriteSparseBool(ref w.cursor, v, UpdateOptions.Upsert));
(ref RowWriter w, boolean v) -> w.row.WriteSparseBool(ref w.cursor, v, UpdateOptions.UPSERT));
}
/**
@@ -183,7 +183,7 @@ public final class RowWriter {
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.WritePrimitive(path, value, LayoutType.DateTime,
(ref RowWriter w, LocalDateTime v) -> w.row.WriteSparseDateTime(ref w.cursor, v, UpdateOptions.Upsert));
(ref RowWriter w, LocalDateTime v) -> w.row.WriteSparseDateTime(ref w.cursor, v, UpdateOptions.UPSERT));
}
/**
@@ -199,7 +199,7 @@ public final class RowWriter {
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.WritePrimitive(path, value, LayoutType.Decimal,
(ref RowWriter w, BigDecimal v) -> w.row.WriteSparseDecimal(ref w.cursor, v, UpdateOptions.Upsert));
(ref RowWriter w, BigDecimal v) -> w.row.WriteSparseDecimal(ref w.cursor, v, UpdateOptions.UPSERT));
}
/**
@@ -215,7 +215,7 @@ public final class RowWriter {
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.WritePrimitive(path, value.clone(), LayoutType.Float128,
(ref RowWriter w, Float128 v) -> w.row.WriteSparseFloat128(ref w.cursor, v.clone(), UpdateOptions.Upsert));
(ref RowWriter w, Float128 v) -> w.row.WriteSparseFloat128(ref w.cursor, v.clone(), UpdateOptions.UPSERT));
}
/**
@@ -231,7 +231,7 @@ public final class RowWriter {
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.WritePrimitive(path, value, LayoutType.Float32,
(ref RowWriter w, float v) -> w.row.WriteSparseFloat32(ref w.cursor, v, UpdateOptions.Upsert));
(ref RowWriter w, float v) -> w.row.WriteSparseFloat32(ref w.cursor, v, UpdateOptions.UPSERT));
}
/**
@@ -247,7 +247,7 @@ public final class RowWriter {
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.WritePrimitive(path, value, LayoutType.Float64,
(ref RowWriter w, double v) -> w.row.WriteSparseFloat64(ref w.cursor, v, UpdateOptions.Upsert));
(ref RowWriter w, double v) -> w.row.WriteSparseFloat64(ref w.cursor, v, UpdateOptions.UPSERT));
}
/**
@@ -263,7 +263,7 @@ public final class RowWriter {
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.WritePrimitive(path, value, LayoutType.Guid,
(ref RowWriter w, UUID v) -> w.row.WriteSparseGuid(ref w.cursor, v, UpdateOptions.Upsert));
(ref RowWriter w, UUID v) -> w.row.WriteSparseGuid(ref w.cursor, v, UpdateOptions.UPSERT));
}
/**
@@ -279,7 +279,7 @@ public final class RowWriter {
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.WritePrimitive(path, value, LayoutType.Int16,
(ref RowWriter w, short v) -> w.row.WriteSparseInt16(ref w.cursor, v, UpdateOptions.Upsert));
(ref RowWriter w, short v) -> w.row.WriteSparseInt16(ref w.cursor, v, UpdateOptions.UPSERT));
}
/**
@@ -289,13 +289,13 @@ public final class RowWriter {
* @param value The value to write.
* @return Success if the write is successful, an error code otherwise.
*/
public Result WriteInt32(UtfAnyString path, int value) {
public Result writeInt32(UtfAnyString path, int value) {
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not
// converted by C# to Java Converter:
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.WritePrimitive(path, value, LayoutType.Int32,
(ref RowWriter w, int v) -> w.row.WriteSparseInt32(ref w.cursor, v, UpdateOptions.Upsert));
(ref RowWriter w, int v) -> w.row.WriteSparseInt32(ref w.cursor, v, UpdateOptions.UPSERT));
}
/**
@@ -311,7 +311,7 @@ public final class RowWriter {
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.WritePrimitive(path, value, LayoutType.Int64,
(ref RowWriter w, long v) -> w.row.WriteSparseInt64(ref w.cursor, v, UpdateOptions.Upsert));
(ref RowWriter w, long v) -> w.row.WriteSparseInt64(ref w.cursor, v, UpdateOptions.UPSERT));
}
/**
@@ -327,7 +327,7 @@ public final class RowWriter {
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.WritePrimitive(path, value, LayoutType.Int8,
(ref RowWriter w, byte v) -> w.row.WriteSparseInt8(ref w.cursor, v, UpdateOptions.Upsert));
(ref RowWriter w, byte v) -> w.row.WriteSparseInt8(ref w.cursor, v, UpdateOptions.UPSERT));
}
/**
@@ -343,7 +343,7 @@ public final class RowWriter {
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.WritePrimitive(path, value.clone(), LayoutType.MongoDbObjectId, (ref RowWriter w,
MongoDbObjectId v) -> w.row.WriteSparseMongoDbObjectId(ref w.cursor, v.clone(), UpdateOptions.Upsert));
MongoDbObjectId v) -> w.row.WriteSparseMongoDbObjectId(ref w.cursor, v.clone(), UpdateOptions.UPSERT));
}
/**
@@ -358,7 +358,7 @@ public final class RowWriter {
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.WritePrimitive(path, NullValue.Default, LayoutType.Null,
(ref RowWriter w, NullValue v) -> w.row.WriteSparseNull(ref w.cursor, v.clone(), UpdateOptions.Upsert));
(ref RowWriter w, NullValue v) -> w.row.WriteSparseNull(ref w.cursor, v.clone(), UpdateOptions.UPSERT));
}
public <TContext> Result WriteScope(UtfAnyString path, TypeArgument typeArg, TContext context,
@@ -379,7 +379,7 @@ public final class RowWriter {
new Reference<RowCursor>(this.cursor);
Out<RowCursor> tempOut_nestedScope =
new Out<RowCursor>();
this.row.writeSparseObject(tempRef_cursor, scopeType, UpdateOptions.Upsert);
this.row.writeSparseObject(tempRef_cursor, scopeType, UpdateOptions.UPSERT);
nestedScope = tempOut_nestedScope.get();
this.cursor = tempRef_cursor.argValue;
break;
@@ -391,7 +391,7 @@ public final class RowWriter {
new Reference<RowCursor>(this.cursor);
Out<RowCursor> tempOut_nestedScope2 =
new Out<RowCursor>();
this.row.writeSparseArray(tempRef_cursor2, scopeType, UpdateOptions.Upsert);
this.row.writeSparseArray(tempRef_cursor2, scopeType, UpdateOptions.UPSERT);
nestedScope = tempOut_nestedScope2.get();
this.cursor = tempRef_cursor2.argValue;
break;
@@ -404,7 +404,7 @@ public final class RowWriter {
Out<RowCursor> tempOut_nestedScope3 =
new Out<RowCursor>();
this.row.writeTypedArray(tempRef_cursor3, scopeType, typeArg.typeArgs().clone(),
UpdateOptions.Upsert, tempOut_nestedScope3);
UpdateOptions.UPSERT, tempOut_nestedScope3);
nestedScope = tempOut_nestedScope3.get();
this.cursor = tempRef_cursor3.argValue;
@@ -418,7 +418,7 @@ public final class RowWriter {
Out<RowCursor> tempOut_nestedScope4 =
new Out<RowCursor>();
this.row.writeSparseTuple(tempRef_cursor4, scopeType, typeArg.typeArgs().clone(),
UpdateOptions.Upsert, tempOut_nestedScope4);
UpdateOptions.UPSERT, tempOut_nestedScope4);
nestedScope = tempOut_nestedScope4.get();
this.cursor = tempRef_cursor4.argValue;
@@ -432,7 +432,7 @@ public final class RowWriter {
Out<RowCursor> tempOut_nestedScope5 =
new Out<RowCursor>();
this.row.writeTypedTuple(tempRef_cursor5, scopeType, typeArg.typeArgs().clone(),
UpdateOptions.Upsert);
UpdateOptions.UPSERT);
nestedScope = tempOut_nestedScope5.get();
this.cursor = tempRef_cursor5.argValue;
@@ -446,7 +446,7 @@ public final class RowWriter {
Out<RowCursor> tempOut_nestedScope6 =
new Out<RowCursor>();
this.row.writeTypedTuple(tempRef_cursor6, scopeType, typeArg.typeArgs().clone(),
UpdateOptions.Upsert);
UpdateOptions.UPSERT);
nestedScope = tempOut_nestedScope6.get();
this.cursor = tempRef_cursor6.argValue;
@@ -460,7 +460,7 @@ public final class RowWriter {
Out<RowCursor> tempOut_nestedScope7 =
new Out<RowCursor>();
this.row.writeTypedTuple(tempRef_cursor7, scopeType, typeArg.typeArgs().clone(),
UpdateOptions.Upsert);
UpdateOptions.UPSERT);
nestedScope = tempOut_nestedScope7.get();
this.cursor = tempRef_cursor7.argValue;
@@ -474,7 +474,7 @@ public final class RowWriter {
Out<RowCursor> tempOut_nestedScope8 =
new Out<RowCursor>();
this.row.writeNullable(tempRef_cursor8, scopeType, typeArg.typeArgs().clone(),
UpdateOptions.Upsert, func != null);
UpdateOptions.UPSERT, func != null);
nestedScope = tempOut_nestedScope8.get();
this.cursor = tempRef_cursor8.argValue;
@@ -488,7 +488,7 @@ public final class RowWriter {
new Reference<RowCursor>(this.cursor);
Out<RowCursor> tempOut_nestedScope9 =
new Out<RowCursor>();
this.row.writeSparseUDT(tempReference_cursor9, scopeType, udt, UpdateOptions.Upsert, tempOut_nestedScope9);
this.row.writeSparseUDT(tempReference_cursor9, scopeType, udt, UpdateOptions.UPSERT, tempOut_nestedScope9);
nestedScope = tempOut_nestedScope9.get();
this.cursor = tempReference_cursor9.get();
break;
@@ -502,7 +502,7 @@ public final class RowWriter {
Out<RowCursor> tempOut_nestedScope10 =
new Out<RowCursor>();
this.row.writeTypedSet(tempRef_cursor10, scopeType, typeArg.typeArgs().clone(),
UpdateOptions.Upsert);
UpdateOptions.UPSERT);
nestedScope = tempOut_nestedScope10.get();
this.cursor = tempRef_cursor10.argValue;
@@ -516,7 +516,7 @@ public final class RowWriter {
Out<RowCursor> tempOut_nestedScope11 =
new Out<RowCursor>();
this.row.writeTypedMap(tempRef_cursor11, scopeType, typeArg.typeArgs().clone(),
UpdateOptions.Upsert);
UpdateOptions.UPSERT);
nestedScope = tempOut_nestedScope11.get();
this.cursor = tempRef_cursor11.argValue;
@@ -582,7 +582,7 @@ public final class RowWriter {
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.WritePrimitive(path, value, LayoutType.Utf8,
(ref RowWriter w, String v) -> w.row.WriteSparseString(ref w.cursor, Utf8Span.TranscodeUtf16(v),
UpdateOptions.Upsert));
UpdateOptions.UPSERT));
}
/**
@@ -598,7 +598,7 @@ public final class RowWriter {
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.WritePrimitive(path, value, LayoutType.Utf8,
(ref RowWriter w, Utf8Span v) -> w.row.WriteSparseString(ref w.cursor, v, UpdateOptions.Upsert));
(ref RowWriter w, Utf8Span v) -> w.row.WriteSparseString(ref w.cursor, v, UpdateOptions.UPSERT));
}
/**
@@ -619,7 +619,7 @@ public final class RowWriter {
//ORIGINAL LINE: return this.WritePrimitive(path, value, LayoutType.UInt16, (ref RowWriter w, ushort v) => w
// .row.WriteSparseUInt16(ref w.cursor, v, UpdateOptions.Upsert));
return this.WritePrimitive(path, value, LayoutType.UInt16,
(ref RowWriter w, short v) -> w.row.WriteSparseUInt16(ref w.cursor, v, UpdateOptions.Upsert));
(ref RowWriter w, short v) -> w.row.WriteSparseUInt16(ref w.cursor, v, UpdateOptions.UPSERT));
}
/**
@@ -631,7 +631,7 @@ public final class RowWriter {
*/
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public Result WriteUInt32(UtfAnyString path, uint value)
public Result WriteUInt32(UtfAnyString path, int value) {
public Result writeUInt32(UtfAnyString path, int value) {
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not
// converted by C# to Java Converter:
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
@@ -640,7 +640,7 @@ public final class RowWriter {
//ORIGINAL LINE: return this.WritePrimitive(path, value, LayoutType.UInt32, (ref RowWriter w, uint v) => w
// .row.WriteSparseUInt32(ref w.cursor, v, UpdateOptions.Upsert));
return this.WritePrimitive(path, value, LayoutType.UInt32,
(ref RowWriter w, int v) -> w.row.WriteSparseUInt32(ref w.cursor, v, UpdateOptions.Upsert));
(ref RowWriter w, int v) -> w.row.WriteSparseUInt32(ref w.cursor, v, UpdateOptions.UPSERT));
}
/**
@@ -661,7 +661,7 @@ public final class RowWriter {
//ORIGINAL LINE: return this.WritePrimitive(path, value, LayoutType.UInt64, (ref RowWriter w, ulong v) => w
// .row.WriteSparseUInt64(ref w.cursor, v, UpdateOptions.Upsert));
return this.WritePrimitive(path, value, LayoutType.UInt64,
(ref RowWriter w, long v) -> w.row.WriteSparseUInt64(ref w.cursor, v, UpdateOptions.Upsert));
(ref RowWriter w, long v) -> w.row.WriteSparseUInt64(ref w.cursor, v, UpdateOptions.UPSERT));
}
/**
@@ -682,7 +682,7 @@ public final class RowWriter {
//ORIGINAL LINE: return this.WritePrimitive(path, value, LayoutType.UInt8, (ref RowWriter w, byte v) => w.row
// .WriteSparseUInt8(ref w.cursor, v, UpdateOptions.Upsert));
return this.WritePrimitive(path, value, LayoutType.UInt8,
(ref RowWriter w, byte v) -> w.row.WriteSparseUInt8(ref w.cursor, v, UpdateOptions.Upsert));
(ref RowWriter w, byte v) -> w.row.WriteSparseUInt8(ref w.cursor, v, UpdateOptions.UPSERT));
}
/**
@@ -699,7 +699,7 @@ public final class RowWriter {
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.WritePrimitive(path, value.clone(), LayoutType.UnixDateTime,
(ref RowWriter w, UnixDateTime v) -> w.row.WriteSparseUnixDateTime(ref w.cursor, v.clone(),
UpdateOptions.Upsert));
UpdateOptions.UPSERT));
}
/**
@@ -715,7 +715,7 @@ public final class RowWriter {
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.WritePrimitive(path, value, LayoutType.VarInt,
(ref RowWriter w, long v) -> w.row.WriteSparseVarInt(ref w.cursor, v, UpdateOptions.Upsert));
(ref RowWriter w, long v) -> w.row.WriteSparseVarInt(ref w.cursor, v, UpdateOptions.UPSERT));
}
/**
@@ -736,7 +736,7 @@ public final class RowWriter {
//ORIGINAL LINE: return this.WritePrimitive(path, value, LayoutType.VarUInt, (ref RowWriter w, ulong v) => w
// .row.WriteSparseVarUInt(ref w.cursor, v, UpdateOptions.Upsert));
return this.WritePrimitive(path, value, LayoutType.VarUInt,
(ref RowWriter w, long v) -> w.row.WriteSparseVarUInt(ref w.cursor, v, UpdateOptions.Upsert));
(ref RowWriter w, long v) -> w.row.WriteSparseVarUInt(ref w.cursor, v, UpdateOptions.UPSERT));
}
public RowWriter clone() {

View File

@@ -9,14 +9,19 @@ import com.azure.data.cosmos.serialization.hybridrow.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull;
/**
* An optional interface that indicates a {@link LayoutType{T}} can also read using a {@link Utf8String}.
*/
public interface ILayoutUtf8SpanReadable extends ILayoutType {
Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Utf8String> value);
@Nonnull
Result readFixedSpan(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Utf8String> value);
Result readSparse(RowBuffer buffer, RowCursor scope, Out<Utf8String> value);
@Nonnull
Result readSparseSpan(RowBuffer buffer, RowCursor scope, Out<Utf8String> value);
Result ReadVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Utf8String> value);
@Nonnull
Result readVariableSpan(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Utf8String> value);
}

View File

@@ -8,16 +8,22 @@ import com.azure.data.cosmos.serialization.hybridrow.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull;
/**
* An optional interface that indicates a {@link LayoutType{T}} can also write using a {@link Utf8String}
*/
public interface ILayoutUtf8SpanWritable extends ILayoutType {
@Nonnull
Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Utf8String value);
@Nonnull
Result writeSparse(RowBuffer buffer, RowCursor edit, Utf8String value);
@Nonnull
Result writeSparse(RowBuffer buffer, RowCursor edit, Utf8String value, UpdateOptions options);
@Nonnull
Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, Utf8String value);
}

View File

@@ -34,7 +34,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
*/
public final class Layout {
public static final Layout EMPTY = SystemSchema.LayoutResolver.resolve(SystemSchema.EmptySchemaId);
public static final Layout EMPTY = SystemSchema.layoutResolver.resolve(SystemSchema.EMPTY_SCHEMA_ID);
private final String name;
private final int numBitmaskBytes;

View File

@@ -19,6 +19,7 @@ public final class LayoutArray extends LayoutIndexedScope {
super(immutable ? IMMUTABLE_ARRAY_SCOPE : ARRAY_SCOPE, immutable, false, false, false, false);
}
@Nonnull
public String name() {
return this.isImmutable() ? "im_array" : "array";
}
@@ -30,7 +31,7 @@ public final class LayoutArray extends LayoutIndexedScope {
@Nonnull final RowCursor edit,
@Nonnull final TypeArgumentList typeArgs,
@Nonnull Out<RowCursor> value) {
return this.writeScope(buffer, edit, typeArgs, UpdateOptions.Upsert, value);
return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value);
}
@Override

View File

@@ -4,11 +4,11 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out;
import com.azure.data.cosmos.core.Reference;
import com.azure.data.cosmos.serialization.hybridrow.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull;
import java.util.List;
import static com.google.common.base.Preconditions.checkArgument;
@@ -23,11 +23,17 @@ public final class LayoutBinary extends LayoutType<byte[]> implements ILayoutSpa
return false;
}
public Result WriteSparse(RowBuffer buffer, RowCursor edit, ReadOnlySequence<Byte> value) {
return writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
@Nonnull
public String name() {
return "binary";
}
@Override
@Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<byte[]> value) {
ReadOnlySpan<Byte> span;
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
@@ -40,7 +46,7 @@ public final class LayoutBinary extends LayoutType<byte[]> implements ILayoutSpa
return result;
}
public Result ReadFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<ReadOnlySpan<Byte>> value) {
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<ReadOnlySpan<Byte>> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
checkArgument(column.size() >= 0);
@@ -54,20 +60,6 @@ public final class LayoutBinary extends LayoutType<byte[]> implements ILayoutSpa
return Result.SUCCESS;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public override Result ReadSparse(ref RowBuffer b, ref RowCursor edit, out byte[] value)
@Override
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<byte[]> value) {
ReadOnlySpan<Byte> span;
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these cannot be converted using the 'Out' helper class unless the method is within the code being modified:
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: Result r = this.ReadSparse(ref b, ref edit, out ReadOnlySpan<byte> span);
Result r = this.ReadSparse(buffer, edit, out span);
value.set((r == Result.SUCCESS) ? span.ToArray() :)
default
return r;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public Result ReadSparse(ref RowBuffer b, ref RowCursor edit, out ReadOnlySpan<byte> value)
public Result ReadSparse(RowBuffer buffer, RowCursor edit, Out<ReadOnlySpan<Byte>> value) {
@@ -84,16 +76,15 @@ public final class LayoutBinary extends LayoutType<byte[]> implements ILayoutSpa
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public override Result ReadVariable(ref RowBuffer b, ref RowCursor scope, LayoutColumn col, out
// byte[] value)
//ORIGINAL LINE: public override Result ReadSparse(ref RowBuffer b, ref RowCursor edit, out byte[] value)
@Override
public Result readVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<byte[]> value) {
@Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<byte[]> value) {
ReadOnlySpan<Byte> span;
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these cannot be converted using the 'Out' helper class unless the method is within the code being modified:
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: Result r = this.ReadVariable(ref b, ref scope, col, out ReadOnlySpan<byte> span);
Result r = this.ReadVariable(buffer, scope, column, out span);
//ORIGINAL LINE: Result r = this.ReadSparse(ref b, ref edit, out ReadOnlySpan<byte> span);
Result r = this.ReadSparse(buffer, edit, out span);
value.set((r == Result.SUCCESS) ? span.ToArray() :)
default
return r;
@@ -115,12 +106,20 @@ public final class LayoutBinary extends LayoutType<byte[]> implements ILayoutSpa
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public override Result WriteFixed(ref RowBuffer b, ref RowCursor scope, LayoutColumn col, byte[]
// value)
//ORIGINAL LINE: public override Result ReadVariable(ref RowBuffer b, ref RowCursor scope, LayoutColumn col, out
// byte[] value)
@Override
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, byte[] value) {
checkArgument(value != null);
return this.writeFixed(buffer, scope, column, new ReadOnlySpan<Byte>(value));
@Nonnull
public Result readVariable(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<byte[]> value) {
ReadOnlySpan<Byte> span;
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: Result r = this.ReadVariable(ref b, ref scope, col, out ReadOnlySpan<byte> span);
Result r = this.ReadVariable(buffer, scope, column, out span);
value.set((r == Result.SUCCESS) ? span.ToArray() :)
default
return r;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
@@ -159,9 +158,20 @@ public final class LayoutBinary extends LayoutType<byte[]> implements ILayoutSpa
return Result.SUCCESS;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public override Result WriteFixed(ref RowBuffer b, ref RowCursor scope, LayoutColumn col, byte[]
// value)
@Override
@Nonnull
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, byte[] value) {
checkArgument(value != null);
return this.writeFixed(buffer, scope, column, new ReadOnlySpan<Byte>(value));
}
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, byte[] value) {
return writeSparse(buffer, edit, value, UpdateOptions.Upsert);
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
@@ -169,6 +179,7 @@ public final class LayoutBinary extends LayoutType<byte[]> implements ILayoutSpa
// UpdateOptions options = UpdateOptions.Upsert)
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, byte[] value,
UpdateOptions options) {
checkArgument(value != null);
@@ -177,10 +188,6 @@ public final class LayoutBinary extends LayoutType<byte[]> implements ILayoutSpa
return this.WriteSparse(buffer, edit, new ReadOnlySpan<Byte>(value), options);
}
public Result writeSparse(RowBuffer buffer, RowCursor edit, Byte value) {
return writeSparse(buffer, edit, value, UpdateOptions.Upsert);
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public Result WriteSparse(ref RowBuffer b, ref RowCursor edit, ReadOnlySpan<byte> value,
// UpdateOptions options = UpdateOptions.Upsert)
@@ -197,32 +204,25 @@ public final class LayoutBinary extends LayoutType<byte[]> implements ILayoutSpa
return Result.SUCCESS;
}
public Result WriteSparse(RowBuffer b, RowCursor edit, ReadOnlySequence<Byte> value) {
return writeSparse(b, edit, value, UpdateOptions.Upsert);
public Result writeSparse(RowBuffer buffer, RowCursor edit, Byte value) {
return writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public Result WriteSparse(ref RowBuffer b, ref RowCursor edit, ReadOnlySequence<byte> value,
// UpdateOptions options = UpdateOptions.Upsert)
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
public Result WriteSparse(RowBuffer b, RowCursor edit, ReadOnlySequence<Byte> value, UpdateOptions options) {
public Result WriteSparse(RowBuffer buffer, RowCursor edit, ReadOnlySequence<Byte> value, UpdateOptions options) {
Result result = LayoutType.prepareSparseWrite(b, edit, this.typeArg(), options);
Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options);
if (result != Result.SUCCESS) {
return result;
}
b.writeSparseBinary(edit, value, options);
buffer.writeSparseBinary(edit, value, options);
return Result.SUCCESS;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public override Result WriteVariable(ref RowBuffer b, ref RowCursor scope, LayoutColumn col,
// byte[] value)
@Override
public Result writeVariable(RowBuffer buffer, RowCursor scope,
LayoutColumn column, byte[] value) {
@Nonnull
public Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, byte[] value) {
checkArgument(value != null);
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: return this.WriteVariable(ref b, ref scope, col, new ReadOnlySpan<byte>(value));

View File

@@ -30,6 +30,7 @@ public final class LayoutBoolean extends LayoutType<Boolean> {
}
@Override
@Nonnull
public String name() {
return "bool";
}
@@ -133,7 +134,8 @@ public final class LayoutBoolean extends LayoutType<Boolean> {
}
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Boolean value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.Upsert);
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
}

View File

@@ -19,28 +19,35 @@ import com.azure.data.cosmos.serialization.hybridrow.schemas.TaggedPropertyType;
import com.azure.data.cosmos.serialization.hybridrow.schemas.TuplePropertyType;
import com.azure.data.cosmos.serialization.hybridrow.schemas.TypeKind;
import com.azure.data.cosmos.serialization.hybridrow.schemas.UdtPropertyType;
import com.google.common.base.Strings;
import tangible.ListHelper;
import javax.annotation.Nonnull;
import java.util.List;
import java.util.Optional;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Strings.lenientFormat;
/**
* Converts a logical schema into a physical layout.
*/
public final class LayoutCompiler {
/**
* Compiles a logical schema into a physical layout that can be used to read and write rows.
* Compiles a logical schema into a physical layout that can be used to read and write rows
*
* @param ns The namespace within which <paramref name="schema" /> is defined.
* @param schema The logical schema to produce a layout for.
* @return The layout for the schema.
* @param ns The namespace within which {@code schema} is defined
* @param schema The logical schema to produce a layout for
* @return The layout for the schema
*/
public static Layout Compile(Namespace ns, Schema schema) {
checkArgument(ns != null);
checkArgument(schema != null);
@Nonnull
public static Layout compile(@Nonnull final Namespace ns, @Nonnull final Schema schema) {
checkNotNull(ns, "expected non-null ns");
checkNotNull(schema, "expected non-null schema");
checkArgument(schema.type() == TypeKind.Schema);
checkArgument(!tangible.StringHelper.isNullOrWhiteSpace(schema.name()));
checkArgument(!Strings.isNullOrEmpty(schema.name()));
checkArgument(ns.schemas().contains(schema));
LayoutBuilder builder = new LayoutBuilder(schema.name(), schema.schemaId());
@@ -63,7 +70,6 @@ public final class LayoutCompiler {
if (!p.propertyType().nullable()) {
throw new LayoutCompilationException("Non-nullable sparse column are not supported.");
}
ObjectPropertyType op = (ObjectPropertyType)p.propertyType();
builder.addObjectScope(p.path(), type);
LayoutCompiler.addProperties(builder, ns, type.layoutCode(), op.properties());
@@ -94,52 +100,52 @@ public final class LayoutCompiler {
}
default: {
PropertyType tempVar = p.propertyType();
PrimitivePropertyType pp = tempVar instanceof PrimitivePropertyType ?
(PrimitivePropertyType)tempVar : null;
if (pp != null) {
if (p.propertyType() instanceof PrimitivePropertyType) {
PrimitivePropertyType pp = (PrimitivePropertyType) p.propertyType();
switch (pp.storage()) {
case FIXED:
if (LayoutCodeTraits.clearImmutableBit(scope) != LayoutCode.SCHEMA) {
throw new LayoutCompilationException("Cannot have fixed storage within a sparse " +
"scope.");
throw new LayoutCompilationException(
"Cannot have fixed storage within a sparse scope.");
}
if (type.isNull() && !pp.nullable()) {
throw new LayoutCompilationException("Non-nullable null columns are not supported" +
".");
throw new LayoutCompilationException(
"Non-nullable null columns are not supported.");
}
builder.addFixedColumn(p.path(), type, pp.nullable(), pp.length());
break;
case VARIABLE:
if (LayoutCodeTraits.clearImmutableBit(scope) != LayoutCode.SCHEMA) {
throw new LayoutCompilationException("Cannot have variable storage within a " +
"sparse scope.");
throw new LayoutCompilationException(
"Cannot have variable storage within a sparse scope.");
}
if (!pp.nullable()) {
throw new LayoutCompilationException("Non-nullable variable columns are not " +
"supported.");
throw new LayoutCompilationException(
"Non-nullable variable columns are not supported.");
}
builder.addVariableColumn(p.path(), type, pp.length());
break;
case SPARSE:
if (!pp.nullable()) {
throw new LayoutCompilationException("Non-nullable sparse columns are not " +
"supported.");
throw new LayoutCompilationException(
"Non-nullable sparse columns are not supported.");
}
builder.addSparseColumn(p.path(), type);
break;
default:
throw new LayoutCompilationException(String.format("Unknown storage specification: " +
"%1$s", pp.storage()));
throw new LayoutCompilationException(
lenientFormat("Unknown storage specification: %s", pp.storage()));
}
} else {
throw new LayoutCompilationException(String.format("Unknown property type: %1$s",
type.name()));
throw new LayoutCompilationException(
lenientFormat("Unknown property type: %s", type.name()));
}
break;
@@ -150,152 +156,187 @@ public final class LayoutCompiler {
private static LayoutType logicalToPhysicalType(Namespace ns, PropertyType logicalType,
Out<TypeArgumentList> typeArgs) {
typeArgs.setAndGet(TypeArgumentList.EMPTY);
boolean tempVar =
(logicalType instanceof ScopePropertyType ? (ScopePropertyType)logicalType : null).immutable();
boolean immutable =
(logicalType instanceof ScopePropertyType ? (ScopePropertyType)logicalType : null) == null ? null :
tempVar != null && tempVar;
typeArgs.set(TypeArgumentList.EMPTY);
boolean immutable = logicalType instanceof ScopePropertyType && ((ScopePropertyType) logicalType).immutable();
switch (logicalType.type()) {
case Null:
return LayoutTypes.NULL;
case Boolean:
return LayoutTypes.BOOLEAN;
case Int8:
return LayoutTypes.INT_8;
case Int16:
return LayoutTypes.INT_16;
case Int32:
return LayoutTypes.INT_32;
case Int64:
return LayoutTypes.INT_64;
case UInt8:
return LayoutTypes.UINT_8;
case UInt16:
return LayoutTypes.UINT_16;
case UInt32:
return LayoutTypes.UINT_32;
case UInt64:
return LayoutTypes.UINT_64;
case Float32:
return LayoutTypes.FLOAT_32;
case Float64:
return LayoutTypes.FLOAT_64;
case Float128:
return LayoutTypes.FLOAT_128;
case Decimal:
return LayoutTypes.DECIMAL;
case DateTime:
return LayoutTypes.DATE_TIME;
case UnixDateTime:
return LayoutTypes.UNIX_DATE_TIME;
case Guid:
return LayoutTypes.GUID;
case MongoDbObjectId:
throw new UnsupportedOperationException();
// return LayoutTypes.MONGO_DB_OBJECT_ID;
case Utf8:
return LayoutTypes.UTF_8;
case Binary:
return LayoutTypes.BINARY;
case VarInt:
return LayoutTypes.VAR_INT;
case VarUInt:
return LayoutTypes.VAR_UINT;
case Object:
return immutable ? LayoutTypes.IMMUTABLE_OBJECT : LayoutTypes.OBJECT;
case Array:
ArrayPropertyType ap = (ArrayPropertyType)logicalType;
if ((ap.items() != null) && (ap.items().type() != TypeKind.Any)) {
TypeArgumentList itemTypeArgs = new TypeArgumentList();
Out<TypeArgumentList> tempOut_itemTypeArgs = new Out<TypeArgumentList>();
LayoutType itemType = LayoutCompiler.logicalToPhysicalType(ns, ap.items(), tempOut_itemTypeArgs);
itemTypeArgs = tempOut_itemTypeArgs.get();
case Array: {
assert logicalType instanceof ArrayPropertyType;
ArrayPropertyType ap = (ArrayPropertyType) logicalType;
if (ap.items() != null && (ap.items().type() != TypeKind.Any)) {
final Out<TypeArgumentList> out = new Out<>();
LayoutType itemType = LayoutCompiler.logicalToPhysicalType(ns, ap.items(), out);
TypeArgumentList itemTypeArgs = out.get();
if (ap.items().nullable()) {
itemTypeArgs = new TypeArgumentList(new TypeArgument[] { new TypeArgument(itemType,
itemTypeArgs) });
itemTypeArgs = new TypeArgumentList(new TypeArgument(itemType, itemTypeArgs));
itemType = itemType.isImmutable() ? LayoutTypes.IMMUTABLE_NULLABLE : LayoutTypes.NULLABLE;
}
typeArgs.setAndGet(new TypeArgumentList(new TypeArgument[] { new TypeArgument(itemType,
itemTypeArgs) }));
typeArgs.set(new TypeArgumentList(new TypeArgument(itemType, itemTypeArgs)));
return immutable ? LayoutTypes.IMMUTABLE_TYPED_ARRAY : LayoutTypes.TYPED_ARRAY;
}
return immutable ? LayoutTypes.IMMUTABLE_ARRAY : LayoutTypes.ARRAY;
case SET:
SetPropertyType sp = (SetPropertyType)logicalType;
}
case SET: {
assert logicalType instanceof SetPropertyType;
SetPropertyType sp = (SetPropertyType) logicalType;
if ((sp.items() != null) && (sp.items().type() != TypeKind.Any)) {
TypeArgumentList itemTypeArgs = new TypeArgumentList();
Out<TypeArgumentList> tempOut_itemTypeArgs2 = new Out<TypeArgumentList>();
LayoutType itemType = LayoutCompiler.logicalToPhysicalType(ns, sp.items(),
tempOut_itemTypeArgs2);
itemTypeArgs = tempOut_itemTypeArgs2.get();
final Out<TypeArgumentList> out = new Out<>();
LayoutType itemType = LayoutCompiler.logicalToPhysicalType(ns, sp.items(), out);
TypeArgumentList itemTypeArgs = out.get();
if (sp.items().nullable()) {
itemTypeArgs = new TypeArgumentList(new TypeArgument[] { new TypeArgument(itemType,
itemTypeArgs) });
itemTypeArgs = new TypeArgumentList(new TypeArgument(itemType, itemTypeArgs));
itemType = itemType.isImmutable() ? LayoutTypes.IMMUTABLE_NULLABLE : LayoutTypes.NULLABLE;
}
typeArgs.setAndGet(new TypeArgumentList(new TypeArgument[] { new TypeArgument(itemType,
itemTypeArgs) }));
typeArgs.set(new TypeArgumentList(new TypeArgument(itemType, itemTypeArgs)));
return immutable ? LayoutTypes.IMMUTABLE_TYPED_SET : LayoutTypes.TYPED_SET;
}
// TODO(283638): implement sparse set.
throw new LayoutCompilationException(String.format("Unknown property type: %1$s",
logicalType.type()));
// TODO(283638): implement sparse set
throw new LayoutCompilationException(lenientFormat(
"Unknown property type: %s",
logicalType.type()
));
}
case MAP: {
assert logicalType instanceof MapPropertyType;
MapPropertyType mp = (MapPropertyType) logicalType;
if (mp.keys() != null && (mp.keys().type() != TypeKind.Any) && (mp.values() != null) && (mp.values().type() != TypeKind.Any)) {
final Out<TypeArgumentList> out = new Out<>();
LayoutType keyType = LayoutCompiler.logicalToPhysicalType(ns, mp.keys(), out);
TypeArgumentList keyTypeArgs = out.get();
case MAP:
MapPropertyType mp = (MapPropertyType)logicalType;
if ((mp.keys() != null) && (mp.keys().type() != TypeKind.Any) && (mp.values() != null) && (mp.values().type() != TypeKind.Any)) {
TypeArgumentList keyTypeArgs = new TypeArgumentList();
Out<TypeArgumentList> tempOut_keyTypeArgs = new Out<TypeArgumentList>();
LayoutType keyType = LayoutCompiler.logicalToPhysicalType(ns, mp.keys(), tempOut_keyTypeArgs);
keyTypeArgs = tempOut_keyTypeArgs.get();
if (mp.keys().nullable()) {
keyTypeArgs = new TypeArgumentList(new TypeArgument[] { new TypeArgument(keyType,
keyTypeArgs) });
keyTypeArgs = new TypeArgumentList(new TypeArgument(keyType, keyTypeArgs));
keyType = keyType.isImmutable() ? LayoutTypes.IMMUTABLE_NULLABLE : LayoutTypes.NULLABLE;
}
TypeArgumentList valueTypeArgs = new TypeArgumentList();
Out<TypeArgumentList> tempOut_valueTypeArgs = new Out<TypeArgumentList>();
LayoutType valueType = LayoutCompiler.logicalToPhysicalType(ns, mp.values(),
tempOut_valueTypeArgs);
valueTypeArgs = tempOut_valueTypeArgs.get();
LayoutType valueType = LayoutCompiler.logicalToPhysicalType(ns, mp.values(), out);
TypeArgumentList valueTypeArgs = out.get();
if (mp.values().nullable()) {
valueTypeArgs = new TypeArgumentList(new TypeArgument[] { new TypeArgument(valueType,
valueTypeArgs) });
valueTypeArgs = new TypeArgumentList(new TypeArgument(valueType, valueTypeArgs));
valueType = valueType.isImmutable() ? LayoutTypes.IMMUTABLE_NULLABLE : LayoutTypes.NULLABLE;
}
typeArgs.setAndGet(new TypeArgumentList(new TypeArgument[]
{
new TypeArgument(keyType, keyTypeArgs),
new TypeArgument(valueType, valueTypeArgs)
}));
typeArgs.set(new TypeArgumentList(
new TypeArgument(keyType, keyTypeArgs),
new TypeArgument(valueType, valueTypeArgs)
));
return immutable ? LayoutTypes.IMMUTABLE_TYPED_MAP : LayoutTypes.TYPED_MAP;
}
// TODO(283638): implement sparse map.
throw new LayoutCompilationException(String.format("Unknown property type: %1$s",
logicalType.type()));
// TODO(283638): implement sparse map
throw new LayoutCompilationException(lenientFormat(
"Unknown property type: %s", logicalType.type())
);
}
case Tuple: {
assert logicalType instanceof TuplePropertyType;
final TuplePropertyType tp = (TuplePropertyType) logicalType;
final TypeArgument[] args = new TypeArgument[tp.items().size()];
final Out<TypeArgumentList> out = new Out<>();
case Tuple:
TuplePropertyType tp = (TuplePropertyType)logicalType;
TypeArgument[] args = new TypeArgument[tp.items().size()];
for (int i = 0; i < tp.items().size(); i++) {
TypeArgumentList itemTypeArgs = new TypeArgumentList();
Out<TypeArgumentList> tempOut_itemTypeArgs3 = new Out<TypeArgumentList>();
LayoutType itemType = LayoutCompiler.logicalToPhysicalType(ns, tp.items().get(i),
tempOut_itemTypeArgs3);
itemTypeArgs = tempOut_itemTypeArgs3.get();
LayoutType itemType = LayoutCompiler.logicalToPhysicalType(ns, tp.items().get(i), out);
TypeArgumentList itemTypeArgs = out.get();
if (tp.items().get(i).nullable()) {
itemTypeArgs = new TypeArgumentList(new TypeArgument[] { new TypeArgument(itemType,
itemTypeArgs) });
itemTypeArgs = new TypeArgumentList(new TypeArgument(itemType, itemTypeArgs));
itemType = itemType.isImmutable() ? LayoutTypes.IMMUTABLE_NULLABLE : LayoutTypes.NULLABLE;
}
@@ -304,33 +345,41 @@ public final class LayoutCompiler {
typeArgs.setAndGet(new TypeArgumentList(args));
return immutable ? LayoutTypes.IMMUTABLE_TYPED_TUPLE : LayoutTypes.TYPED_TUPLE;
}
case TAGGED: {
case TAGGED:
TaggedPropertyType tg = (TaggedPropertyType)logicalType;
if ((tg.items().size() < TaggedPropertyType.MinTaggedArguments) || (tg.items().size() > TaggedPropertyType.MaxTaggedArguments)) {
throw new LayoutCompilationException(String.format("Invalid number of arguments in Tagged: %1$s " +
"<= %2$s <= %3$s", TaggedPropertyType.MinTaggedArguments, tg.items().size(),
TaggedPropertyType.MaxTaggedArguments));
assert logicalType instanceof TaggedPropertyType;
TaggedPropertyType tg = (TaggedPropertyType) logicalType;
if (tg.items().size() < TaggedPropertyType.MinTaggedArguments || (tg.items().size() > TaggedPropertyType.MaxTaggedArguments)) {
throw new LayoutCompilationException(lenientFormat(
"Invalid number of arguments in Tagged: %s <= %s <= %s",
TaggedPropertyType.MinTaggedArguments,
tg.items().size(),
TaggedPropertyType.MaxTaggedArguments
));
}
TypeArgument[] tgArgs = new TypeArgument[tg.items().size() + 1];
final Out<TypeArgumentList> out = new Out<>();
final TypeArgument[] tgArgs = new TypeArgument[tg.items().size() + 1];
tgArgs[0] = new TypeArgument(LayoutTypes.UINT_8, TypeArgumentList.EMPTY);
for (int i = 0; i < tg.items().size(); i++) {
TypeArgumentList itemTypeArgs = new TypeArgumentList();
Out<TypeArgumentList> tempOut_itemTypeArgs4 = new Out<TypeArgumentList>();
LayoutType itemType = LayoutCompiler.logicalToPhysicalType(ns, tg.items().get(i),
tempOut_itemTypeArgs4);
itemTypeArgs = tempOut_itemTypeArgs4.get();
LayoutType itemType = LayoutCompiler.logicalToPhysicalType(ns, tg.items().get(i), out);
TypeArgumentList itemTypeArgs = out.get();
if (tg.items().get(i).nullable()) {
itemTypeArgs = new TypeArgumentList(new TypeArgument[] { new TypeArgument(itemType,
itemTypeArgs) });
itemTypeArgs = new TypeArgumentList(new TypeArgument(itemType, itemTypeArgs));
itemType = itemType.isImmutable() ? LayoutTypes.IMMUTABLE_NULLABLE : LayoutTypes.NULLABLE;
}
tgArgs[i + 1] = new TypeArgument(itemType, itemTypeArgs);
}
typeArgs.setAndGet(new TypeArgumentList(tgArgs));
typeArgs.set(new TypeArgumentList(tgArgs));
switch (tg.items().size()) {
case 1:
return immutable ? LayoutTypes.IMMUTABLE_TAGGED : LayoutTypes.TAGGED;
@@ -339,32 +388,42 @@ public final class LayoutCompiler {
default:
throw new LayoutCompilationException("Unexpected tagged arity");
}
}
case Schema: {
case Schema:
UdtPropertyType up = (UdtPropertyType)logicalType;
Schema udtSchema;
if (SchemaId.opEquals(up.schemaId(), SchemaId.INVALID)) {
udtSchema = ListHelper.find(ns.schemas(), s = up.name().equals( > s.Name))
assert logicalType instanceof UdtPropertyType;
UdtPropertyType up = (UdtPropertyType) logicalType;
final Optional<Schema> udtSchema;
if (up.schemaId() == SchemaId.INVALID) {
udtSchema = ns.schemas().stream()
.filter(schema -> up.name().equals(schema.name()))
.findFirst();
} else {
udtSchema = ListHelper.find(ns.schemas(), s =
SchemaId.opEquals( > s.SchemaId, up.schemaId()))
if (!udtSchema.name().equals(up.name())) {
throw new LayoutCompilationException(String.format("Ambiguous schema reference: '%1$s:%2$s'",
up.name(), up.schemaId()));
udtSchema = ns.schemas().stream()
.filter(schema -> up.schemaId().equals(schema.schemaId()))
.findFirst();
if (up.name().equals(udtSchema.map(Schema::name).orElse(null))) {
throw new LayoutCompilationException(lenientFormat(
"Ambiguous schema reference: '%s:%s'", up.name(), up.schemaId()
));
}
}
if (udtSchema == null) {
throw new LayoutCompilationException(String.format("Cannot resolve schema reference '%1$s:%2$s'",
up.name(), up.schemaId()));
if (!udtSchema.isPresent()) {
throw new LayoutCompilationException(lenientFormat(
"Cannot resolve schema reference '%s:%s'", up.name(), up.schemaId()
));
}
typeArgs.setAndGet(new TypeArgumentList(udtSchema.schemaId()));
typeArgs.set(new TypeArgumentList(udtSchema.get().schemaId()));
return immutable ? LayoutTypes.IMMUTABLE_UDT : LayoutTypes.UDT;
}
default:
throw new LayoutCompilationException(String.format("Unknown property type: %1$s",
logicalType.type()));
throw new LayoutCompilationException(Strings.lenientFormat(
"Unknown property type: %s", logicalType.type()
));
}
}
}
}

View File

@@ -4,14 +4,12 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out;
import com.azure.data.cosmos.core.Reference;
import com.azure.data.cosmos.serialization.hybridrow.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import com.azure.data.cosmos.serialization.hybridrow.codecs.DateTimeCodec;
import javax.annotation.Nonnull;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import static com.google.common.base.Preconditions.checkArgument;
@@ -26,6 +24,7 @@ public final class LayoutDateTime extends LayoutType<OffsetDateTime> {
return true;
}
@Nonnull
public String name() {
return "datetime";
}
@@ -77,20 +76,21 @@ public final class LayoutDateTime extends LayoutType<OffsetDateTime> {
@Override
@Nonnull
public Result writeSparse(RowBuffer b, RowCursor edit, OffsetDateTime value, UpdateOptions options) {
public Result writeSparse(RowBuffer buffer, RowCursor edit, OffsetDateTime value, UpdateOptions options) {
Result result = LayoutType.prepareSparseWrite(b, edit, this.typeArg(), options);
Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options);
if (result != Result.SUCCESS) {
return result;
}
b.writeSparseDateTime(edit, value, options);
buffer.writeSparseDateTime(edit, value, options);
return Result.SUCCESS;
}
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, OffsetDateTime value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.Upsert);
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
}

View File

@@ -24,6 +24,7 @@ public final class LayoutDecimal extends LayoutType<BigDecimal> {
return true;
}
@Nonnull
public String name() {
return "decimal";
}
@@ -86,6 +87,6 @@ public final class LayoutDecimal extends LayoutType<BigDecimal> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, BigDecimal value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.Upsert);
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
}

View File

@@ -16,21 +16,33 @@ public final class LayoutEndScope extends LayoutScope {
super(LayoutCode.END_SCOPE, false, false, false, false, false, false);
}
@Nonnull
public String name() {
return "end";
}
@Override
@Nonnull
public Result writeScope(RowBuffer buffer, RowCursor scope, TypeArgumentList typeArgs, Out<RowCursor> value) {
return this.writeScope(buffer, scope, typeArgs, UpdateOptions.Upsert, value);
public Result writeScope(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor scope,
@Nonnull final TypeArgumentList typeArgs,
@Nonnull final Out<RowCursor> value) {
return this.writeScope(buffer, scope, typeArgs, UpdateOptions.UPSERT, value);
}
@Override
@Nonnull
public Result writeScope(RowBuffer buffer, RowCursor scope, TypeArgumentList typeArgs, UpdateOptions options, Out<RowCursor> value) {
public Result writeScope(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor scope,
@Nonnull final TypeArgumentList typeArgs,
@Nonnull final UpdateOptions options,
@Nonnull final Out<RowCursor> value) {
assert false : "cannot write an EndScope directly";
value.set(null);
return Result.FAILURE;
}
}

View File

@@ -23,6 +23,7 @@ public final class LayoutFloat128 extends LayoutType<Float128> {
return true;
}
@Nonnull
public String name() {
return "float128";
}
@@ -89,6 +90,6 @@ public final class LayoutFloat128 extends LayoutType<Float128> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Float128 value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.Upsert);
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
}

View File

@@ -4,7 +4,6 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out;
import com.azure.data.cosmos.core.Reference;
import com.azure.data.cosmos.serialization.hybridrow.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
@@ -23,6 +22,7 @@ public final class LayoutFloat32 extends LayoutType<Float> {
return true;
}
@Nonnull
public String name() {
return "float32";
}
@@ -89,6 +89,6 @@ public final class LayoutFloat32 extends LayoutType<Float> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Float value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.Upsert);
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
}

View File

@@ -22,6 +22,7 @@ public final class LayoutFloat64 extends LayoutType<Double> {
return true;
}
@Nonnull
public String name() {
return "float64";
}
@@ -91,6 +92,6 @@ public final class LayoutFloat64 extends LayoutType<Double> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Double value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.Upsert);
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
}

View File

@@ -24,6 +24,7 @@ public final class LayoutGuid extends LayoutType<UUID> {
return true;
}
@Nonnull
public String name() {
return "guid";
}
@@ -90,6 +91,6 @@ public final class LayoutGuid extends LayoutType<UUID> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, UUID value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.Upsert);
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
}

View File

@@ -18,7 +18,7 @@ public abstract class LayoutIndexedScope extends LayoutScope {
}
@Override
public void readSparsePath(@Nonnull final RowBuffer row, @Nonnull final RowCursor edit) {
public void readSparsePath(@Nonnull final RowBuffer buffer, @Nonnull final RowCursor edit) {
edit.pathToken(0);
edit.pathOffset(0);
}

View File

@@ -22,6 +22,7 @@ public final class LayoutInt16 extends LayoutType<Short> {
return true;
}
@Nonnull
public String name() {
return "int16";
}
@@ -88,6 +89,6 @@ public final class LayoutInt16 extends LayoutType<Short> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Short value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.Upsert);
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
}

View File

@@ -22,6 +22,7 @@ public final class LayoutInt32 extends LayoutType<Integer> {
return true;
}
@Nonnull
public String name() {
return "int32";
}
@@ -87,7 +88,7 @@ public final class LayoutInt32 extends LayoutType<Integer> {
@Override
@Nonnull
public Result writeSparse(RowBuffer b, RowCursor edit, Integer value) {
return this.writeSparse(b, edit, value, UpdateOptions.Upsert);
public Result writeSparse(RowBuffer buffer, RowCursor edit, Integer value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
}

View File

@@ -22,6 +22,7 @@ public final class LayoutInt64 extends LayoutType<Long> {
return true;
}
@Nonnull
public String name() {
return "int64";
}
@@ -86,7 +87,7 @@ public final class LayoutInt64 extends LayoutType<Long> {
@Override
@Nonnull
public Result writeSparse(RowBuffer b, RowCursor edit, Long value) {
return this.writeSparse(b, edit, value, UpdateOptions.Upsert);
public Result writeSparse(RowBuffer buffer, RowCursor edit, Long value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
}

View File

@@ -22,6 +22,7 @@ public final class LayoutInt8 extends LayoutType<Byte> {
return true;
}
@Nonnull
public String name() {
return "int8";
}
@@ -88,6 +89,6 @@ public final class LayoutInt8 extends LayoutType<Byte> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Byte value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.Upsert);
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
}

View File

@@ -8,6 +8,8 @@ import com.azure.data.cosmos.serialization.hybridrow.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutMongoDbObjectId extends LayoutType<MongoDbObjectId> {
@@ -20,11 +22,13 @@ public final class LayoutMongoDbObjectId extends LayoutType<MongoDbObjectId> {
}
// ReSharper disable once StringLiteralTypo
@Nonnull
public String name() {
return "mongodbobjectid";
}
@Override
@Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column,
Out<MongoDbObjectId> value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT);
@@ -38,9 +42,10 @@ public final class LayoutMongoDbObjectId extends LayoutType<MongoDbObjectId> {
}
@Override
@Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit,
Out<MongoDbObjectId> value) {
Result result = LayoutType.prepareSparseRead(buffer, edit, this.LayoutCode);
Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode());
if (result != Result.SUCCESS) {
value.setAndGet(null);
return result;
@@ -51,6 +56,7 @@ public final class LayoutMongoDbObjectId extends LayoutType<MongoDbObjectId> {
}
@Override
@Nonnull
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column,
MongoDbObjectId value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT);
@@ -67,6 +73,7 @@ public final class LayoutMongoDbObjectId extends LayoutType<MongoDbObjectId> {
//ORIGINAL LINE: public override Result WriteSparse(ref RowBuffer b, ref RowCursor edit, MongoDbObjectId value,
// UpdateOptions options = UpdateOptions.Upsert)
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit,
MongoDbObjectId value, UpdateOptions options) {
Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg().clone(), options);
@@ -79,8 +86,9 @@ public final class LayoutMongoDbObjectId extends LayoutType<MongoDbObjectId> {
}
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit,
MongoDbObjectId value) {
return writeSparse(buffer, edit, value, UpdateOptions.Upsert);
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
}

View File

@@ -9,11 +9,14 @@ import com.azure.data.cosmos.serialization.hybridrow.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutNull extends LayoutType<NullValue> {
public LayoutNull() {
super(com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.NULL, 0);
super(LayoutCode.NULL, 0);
}
public boolean isFixed() {
@@ -24,64 +27,59 @@ public final class LayoutNull extends LayoutType<NullValue> {
return true;
}
@Nonnull
public String name() {
return "null";
}
@Override
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column,
Out<NullValue> value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT);
value.setAndGet(NullValue.Default);
if (!buffer.get().readBit(scope.get().start(), column.getNullBit().clone())) {
@Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<NullValue> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
value.set(NullValue.Default);
if (!buffer.readBit(scope.start(), column.nullBit())) {
return Result.NOT_FOUND;
}
return Result.SUCCESS;
}
@Override
public Result readSparse(RowBuffer buffer, RowCursor edit,
Out<NullValue> value) {
Result result = prepareSparseRead(buffer, edit, this.LayoutCode);
@Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<NullValue> value) {
Result result = prepareSparseRead(buffer, edit, this.layoutCode());
if (result != Result.SUCCESS) {
value.setAndGet(null);
value.set(null);
return result;
}
value.setAndGet(buffer.get().readSparseNull(edit).clone());
value.set(buffer.readSparseNull(edit));
return Result.SUCCESS;
}
@Override
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column,
NullValue value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT);
if (scope.get().immutable()) {
@Nonnull
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, NullValue value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
if (scope.immutable()) {
return Result.INSUFFICIENT_PERMISSIONS;
}
buffer.get().SetBit(scope.get().start(), column.getNullBit().clone());
buffer.setBit(scope.start(), column.nullBit());
return Result.SUCCESS;
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public override Result WriteSparse(ref RowBuffer b, ref RowCursor edit, NullValue value,
// UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result writeSparse(RowBuffer buffer, RowCursor edit, NullValue value,
UpdateOptions options) {
Result result = prepareSparseWrite(buffer, edit, this.typeArg().clone(), options);
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, NullValue value, UpdateOptions options) {
Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options);
if (result != Result.SUCCESS) {
return result;
}
buffer.get().WriteSparseNull(edit, value.clone(), options);
buffer.writeSparseNull(edit, value, options);
return Result.SUCCESS;
}
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, NullValue value) {
return writeSparse(buffer, edit, value, UpdateOptions.Upsert);
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
}

View File

@@ -4,7 +4,6 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out;
import com.azure.data.cosmos.core.Reference;
import com.azure.data.cosmos.serialization.hybridrow.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
@@ -16,19 +15,25 @@ import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
public final class LayoutNullable extends LayoutIndexedScope {
public LayoutNullable(boolean immutable) {
super(immutable ? com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.IMMUTABLE_NULLABLE_SCOPE :
com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.NULLABLE_SCOPE, immutable, true, true, false, true);
}
public String name() {
return this.Immutable ? "im_nullable" : "nullable";
super(
immutable ? LayoutCode.IMMUTABLE_NULLABLE_SCOPE : LayoutCode.NULLABLE_SCOPE, immutable,
true, true, false, true
);
}
@Override
public int countTypeArgument(@Nonnull final TypeArgumentList value) {
checkNotNull(value, "expected non-null value");
checkArgument(value.count() == 1);
return (LayoutCode.SIZE / Byte.SIZE) + value.get(0).type().countTypeArgument(value.get(0).typeArgs());
return LayoutCode.BYTES + value.get(0).type().countTypeArgument(value.get(0).typeArgs());
}
@Override
@Nonnull
public String name() {
return this.isImmutable() ? "im_nullable" : "nullable";
}
@Override
@@ -40,72 +45,94 @@ public final class LayoutNullable extends LayoutIndexedScope {
return !LayoutCodeTraits.alwaysRequiresTypeCode(edit.scopeTypeArgs().get(0).type().layoutCode());
}
public static Result hasValue(@Nonnull final RowBuffer b, @Nonnull final RowCursor scope) {
checkNotNull(b);
public static Result hasValue(@Nonnull final RowBuffer buffer, @Nonnull final RowCursor scope) {
checkNotNull(buffer);
checkNotNull(scope);
checkArgument(scope.scopeType() instanceof LayoutNullable);
checkArgument(scope.index() == 1 || scope.index() == 2);
checkArgument(scope.scopeTypeArgs().count() == 1);
boolean hasValue = b.readInt8(scope.start()) != 0;
boolean hasValue = buffer.readInt8(scope.start()) != 0;
return hasValue ? Result.SUCCESS : Result.NOT_FOUND;
}
@Override
public TypeArgumentList readTypeArgumentList(
@Nonnull final RowBuffer row, int offset, @Nonnull final Out<Integer> lenInBytes) {
return new TypeArgumentList(LayoutType.readTypeArgument(row, offset, lenInBytes));
@Nonnull final RowBuffer buffer, final int offset, @Nonnull final Out<Integer> lengthInBytes) {
return new TypeArgumentList(LayoutType.readTypeArgument(buffer, offset, lengthInBytes));
}
@Override
public void setImplicitTypeCode(RowCursor edit) {
checkState(edit.index() == 1);
edit.get().cellType(edit.get().scopeTypeArgs().get(0).type());
edit.get().cellTypeArgs(edit.get().scopeTypeArgs().get(0).typeArgs());
edit.cellType(edit.scopeTypeArgs().get(0).type());
edit.cellTypeArgs(edit.scopeTypeArgs().get(0).typeArgs());
}
public Result writeScope(Reference<RowBuffer> b, Reference<RowCursor> edit,
TypeArgumentList typeArgs, boolean hasValue, Out<RowCursor> value) {
return writeScope(b, edit, typeArgs, hasValue, value, UpdateOptions.Upsert);
public Result writeScope(
RowBuffer buffer,
RowCursor edit,
TypeArgumentList typeArgs,
boolean hasValue,
Out<RowCursor> value) {
return this.writeScope(buffer, edit, typeArgs, hasValue, UpdateOptions.UPSERT, value);
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public Result WriteScope(ref RowBuffer b, ref RowCursor edit, TypeArgumentList typeArgs, bool
// hasValue, out RowCursor value, UpdateOptions options = UpdateOptions.Upsert)
public Result writeScope(Reference<RowBuffer> b, Reference<RowCursor> edit,
TypeArgumentList typeArgs, boolean hasValue, Out<RowCursor> value,
UpdateOptions options) {
Result result = LayoutType.prepareSparseWrite(b, edit, new TypeArgument(this, typeArgs.clone()), options);
public Result writeScope(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor edit,
@Nonnull final TypeArgumentList typeArgs,
boolean hasValue,
@Nonnull final UpdateOptions options,
@Nonnull final Out<RowCursor> value) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(edit, "expected non-null edit");
checkNotNull(typeArgs, "expected non-null typeArgs");
checkNotNull(options, "expected non-null options");
checkNotNull(value, "expected non-null value");
Result result = LayoutType.prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs), options);
if (result != Result.SUCCESS) {
value.setAndGet(null);
value.set(null);
return result;
}
b.get().writeNullable(edit, this, typeArgs.clone(), options, hasValue);
buffer.writeNullable(edit, this, typeArgs, options, hasValue);
return Result.SUCCESS;
}
@Override
public Result writeScope(RowBuffer buffer, RowCursor edit,
TypeArgumentList typeArgs, Out<RowCursor> value) {
return writeScope(buffer, edit, typeArgs, UpdateOptions.Upsert, value);
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public override Result WriteScope(ref RowBuffer b, ref RowCursor edit, TypeArgumentList
// typeArgs, out RowCursor value, UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result writeScope(RowBuffer buffer, RowCursor edit,
TypeArgumentList typeArgs, UpdateOptions options, Out<RowCursor> value) {
return this.WriteScope(buffer, edit, typeArgs.clone(), true, value, options);
@Nonnull
public Result writeScope(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor edit,
@Nonnull final TypeArgumentList typeArgs,
@Nonnull final Out<RowCursor> value) {
return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value);
}
@Override
public int writeTypeArgument(Reference<RowBuffer> row, int offset, TypeArgumentList value) {
checkState(value.count() == 1);
row.get().writeSparseTypeCode(offset, this.LayoutCode);
int lenInBytes = (com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE);
lenInBytes += value.get(0).type().writeTypeArgument(row, offset + lenInBytes,
value.get(0).typeArgs().clone());
return lenInBytes;
@Nonnull
public Result writeScope(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor edit,
@Nonnull final TypeArgumentList typeArgs,
@Nonnull final UpdateOptions options,
@Nonnull final Out<RowCursor> value) {
return this.writeScope(buffer, edit, typeArgs, true, options, value);
}
@Override
public int writeTypeArgument(@Nonnull final RowBuffer buffer, int offset, @Nonnull final TypeArgumentList value) {
checkNotNull(buffer);
checkNotNull(value);
checkArgument(offset >= 0);
checkArgument(value.count() == 1);
final TypeArgument typeArg = value.get(0);
buffer.writeSparseTypeCode(offset, this.layoutCode());
return LayoutCode.BYTES + typeArg.type().writeTypeArgument(buffer, offset + LayoutCode.BYTES, typeArg.typeArgs());
}
}

View File

@@ -8,43 +8,46 @@ import com.azure.data.cosmos.serialization.hybridrow.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull;
public final class LayoutObject extends LayoutPropertyScope {
private TypeArgument TypeArg = new TypeArgument();
private TypeArgument typeArg;
public LayoutObject(boolean immutable) {
super(immutable ? com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.IMMUTABLE_OBJECT_SCOPE :
com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.OBJECT_SCOPE, immutable);
this.TypeArg = new TypeArgument(this);
super(immutable ? LayoutCode.IMMUTABLE_OBJECT_SCOPE : LayoutCode.OBJECT_SCOPE, immutable);
this.typeArg = new TypeArgument(this);
}
@Override
@Nonnull
public String name() {
return this.Immutable ? "im_object" : "object";
return this.isImmutable() ? "im_object" : "object";
}
public TypeArgument typeArg() {
return TypeArg;
return this.typeArg;
}
@Override
public Result writeScope(RowBuffer buffer, RowCursor edit,
TypeArgumentList typeArgs, Out<RowCursor> value) {
return writeScope(buffer, edit, typeArgs, UpdateOptions.Upsert, value);
@Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, Out<RowCursor> value) {
return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value);
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public override Result WriteScope(ref RowBuffer b, ref RowCursor edit, TypeArgumentList
// typeArgs, out RowCursor value, UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result writeScope(RowBuffer buffer, RowCursor edit,
TypeArgumentList typeArgs, UpdateOptions options, Out<RowCursor> value) {
Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg().clone(), options);
@Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, UpdateOptions options, Out<RowCursor> value) {
Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options);
if (result != Result.SUCCESS) {
value.setAndGet(null);
return result;
}
buffer.get().WriteSparseObject(edit, this, options, value.clone());
value.set(buffer.writeSparseObject(edit, this, options));
return Result.SUCCESS;
}
}

View File

@@ -7,6 +7,10 @@ import com.azure.data.cosmos.serialization.hybridrow.SchemaId;
import com.azure.data.cosmos.serialization.hybridrow.schemas.Namespace;
import com.azure.data.cosmos.serialization.hybridrow.schemas.Schema;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.concurrent.ConcurrentHashMap;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Strings.lenientFormat;
@@ -19,55 +23,38 @@ import static com.google.common.base.Strings.lenientFormat;
* All members of this class are multi-thread safe.
*/
public final class LayoutResolverNamespace extends LayoutResolver {
private java.util.concurrent.ConcurrentHashMap<Integer, Layout> layoutCache;
private LayoutResolver parent;
private Namespace schemaNamespace;
private final ConcurrentHashMap<SchemaId, Layout> layoutCache;
private final LayoutResolver parent;
private final Namespace schemaNamespace;
public LayoutResolverNamespace(Namespace schemaNamespace) {
public LayoutResolverNamespace(@Nonnull final Namespace schemaNamespace) {
this(schemaNamespace, null);
}
public LayoutResolverNamespace(Namespace schemaNamespace, LayoutResolver parent) {
public LayoutResolverNamespace(@Nonnull final Namespace schemaNamespace, @Nullable final LayoutResolver parent) {
this.schemaNamespace = schemaNamespace;
this.parent = parent;
this.layoutCache = new java.util.concurrent.ConcurrentHashMap<Integer, Layout>();
this.layoutCache = new ConcurrentHashMap<>();
}
public Namespace getNamespace() {
public Namespace namespace() {
return this.schemaNamespace;
}
@Override
public Layout resolve(SchemaId schemaId) {
Layout layout;
// TODO: C# TO JAVA CONVERTER: There is no Java ConcurrentHashMap equivalent to this .NET
// ConcurrentDictionary method:
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
if (this.layoutCache.TryGetValue(schemaId.value(), out layout)) {
return layout;
}
for (Schema s : this.schemaNamespace.schemas()) {
if (SchemaId.opEquals(s.schemaId().clone(),
schemaId.clone())) {
layout = s.compile(this.schemaNamespace);
layout = this.layoutCache.putIfAbsent(schemaId.value(), layout);
return layout;
Layout layout = this.layoutCache.computeIfAbsent(schemaId, id -> {
for (Schema schema : this.namespace().schemas()) {
if (schema.schemaId().equals(id)) {
return schema.compile(this.schemaNamespace);
}
}
}
return this.parent == null ? null : this.parent.resolve(schemaId);
});
layout = this.parent == null ? null : this.parent.resolve(schemaId.clone());
if (layout != null) {
// TODO: C# TO JAVA CONVERTER: There is no Java ConcurrentHashMap equivalent to this .NET
// ConcurrentDictionary method:
boolean succeeded = this.layoutCache.TryAdd(schemaId.value(), layout);
checkState(succeeded);
return layout;
}
throw new IllegalStateException(lenientFormat("Failed to resolve schema %s", schemaId.clone()));
checkState(layout != null, "failed to resolve schema %s", schemaId);
return null;
}
}

View File

@@ -132,10 +132,10 @@ public abstract class LayoutScope extends LayoutType {
return Result.SUCCESS;
}
public void readSparsePath(@Nonnull final RowBuffer row, @Nonnull final RowCursor edit) {
public void readSparsePath(@Nonnull final RowBuffer buffer, @Nonnull final RowCursor edit) {
Out<Integer> pathLenInBytes = new Out<>();
Out<Integer> pathOffset = new Out<>();
edit.pathToken(row.readSparsePathLen(edit.layout(), edit.valueOffset(), pathLenInBytes, pathOffset));
edit.pathToken(buffer.readSparsePathLen(edit.layout(), edit.valueOffset(), pathLenInBytes, pathOffset));
edit.pathOffset(pathOffset.get());
edit.valueOffset(edit.valueOffset() + pathLenInBytes.get());
}
@@ -163,7 +163,7 @@ public abstract class LayoutScope extends LayoutType {
RowCursor scope,
TypeArgumentList typeArgs,
TContext context, WriterFunc<TContext> func) {
return this.writeScope(buffer, scope, typeArgs, context, func, UpdateOptions.Upsert);
return this.writeScope(buffer, scope, typeArgs, context, func, UpdateOptions.UPSERT);
}
@Nonnull

View File

@@ -4,7 +4,6 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out;
import com.azure.data.cosmos.core.Reference;
import com.azure.data.cosmos.serialization.hybridrow.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
@@ -14,21 +13,29 @@ import javax.annotation.Nonnull;
import static com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.IMMUTABLE_TAGGED_SCOPE;
import static com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.TAGGED_SCOPE;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
public final class LayoutTagged extends LayoutIndexedScope {
public LayoutTagged(boolean immutable) {
super(immutable ? IMMUTABLE_TAGGED_SCOPE : TAGGED_SCOPE, immutable, true, true, false, true);
super(immutable ? IMMUTABLE_TAGGED_SCOPE : TAGGED_SCOPE, immutable,
true, true, false, true
);
}
public String name() {
return this.isImmutable() ? "im_tagged_t" : "tagged_t";
}
public int countTypeArgument(TypeArgumentList value) {
@Override
public int countTypeArgument(@Nonnull final TypeArgumentList value) {
checkNotNull(value, "expected non-null value");
checkArgument(value.count() == 2);
return LayoutCode.BYTES + value.get(1).type().countTypeArgument(value.get(1).typeArgs());
}
@Override
@Nonnull
public String name() {
return this.isImmutable() ? "im_tagged_t" : "tagged_t";
}
@Override
public boolean hasImplicitTypeCode(RowCursor edit) {
checkArgument(edit.index() >= 0);
@@ -37,6 +44,7 @@ public final class LayoutTagged extends LayoutIndexedScope {
}
@Override
@Nonnull
public TypeArgumentList readTypeArgumentList(RowBuffer buffer, int offset, Out<Integer> lenInBytes) {
TypeArgument[] typeArgs = new TypeArgument[2];
typeArgs[0] = new TypeArgument(LayoutTypes.UINT_8, TypeArgumentList.EMPTY);
@@ -53,7 +61,7 @@ public final class LayoutTagged extends LayoutIndexedScope {
@Override
@Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, Out<RowCursor> value) {
return this.writeScope(buffer, edit, typeArgs, UpdateOptions.Upsert, value);
return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value);
}
@Override
@@ -73,11 +81,11 @@ public final class LayoutTagged extends LayoutIndexedScope {
}
@Override
public int writeTypeArgument(RowBuffer row, int offset, TypeArgumentList value) {
public int writeTypeArgument(RowBuffer buffer, int offset, TypeArgumentList value) {
checkArgument(value.count() == 2);
row.writeSparseTypeCode(offset, this.layoutCode());
buffer.writeSparseTypeCode(offset, this.layoutCode());
int lenInBytes = LayoutCode.BYTES;
lenInBytes += value.get(1).type().writeTypeArgument(row, offset + lenInBytes, value.get(1).typeArgs());
lenInBytes += value.get(1).type().writeTypeArgument(buffer, offset + lenInBytes, value.get(1).typeArgs());
return lenInBytes;
}
}

View File

@@ -10,26 +10,25 @@ import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
public final class LayoutTagged2 extends LayoutIndexedScope {
public LayoutTagged2(boolean immutable) {
super(
immutable ? LayoutCode.IMMUTABLE_TAGGED2_SCOPE : LayoutCode.TAGGED2_SCOPE,
immutable, true, true, false, true
immutable ? LayoutCode.IMMUTABLE_TAGGED2_SCOPE : LayoutCode.TAGGED2_SCOPE, immutable,
true, true, false, true
);
}
public int countTypeArgument(TypeArgumentList value) {
@Override
public int countTypeArgument(@Nonnull TypeArgumentList value) {
checkNotNull(value, "expected non-null value");
checkState(value.count() == 3);
int lenInBytes = LayoutCode.BYTES;
for (int i = 1; i < value.count(); i++) {
TypeArgument arg = value.get(i);
lenInBytes += arg.type().countTypeArgument(arg.typeArgs());
}
return lenInBytes;
return value.stream()
.map(arg -> arg.type().countTypeArgument(arg.typeArgs()))
.reduce(LayoutCode.BYTES, Integer::sum);
}
@Override
@@ -39,6 +38,8 @@ public final class LayoutTagged2 extends LayoutIndexedScope {
return !LayoutCodeTraits.alwaysRequiresTypeCode(edit.scopeTypeArgs().get(edit.index()).type().layoutCode());
}
@Override
@Nonnull
public String name() {
return this.isImmutable() ? "im_tagged2_t" : "tagged2_t";
}
@@ -69,12 +70,11 @@ public final class LayoutTagged2 extends LayoutIndexedScope {
@Override
@Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, Out<RowCursor> value) {
return this.writeScope(buffer, edit, typeArgs, UpdateOptions.Upsert, value);
return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value);
}
@Override
@Nonnull
@Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, UpdateOptions options,
Out<RowCursor> value) {
@@ -90,16 +90,16 @@ public final class LayoutTagged2 extends LayoutIndexedScope {
}
@Override
public int writeTypeArgument(RowBuffer row, int offset, TypeArgumentList value) {
public int writeTypeArgument(RowBuffer buffer, int offset, TypeArgumentList value) {
checkState(value.count() == 3);
row.writeSparseTypeCode(offset, this.layoutCode());
buffer.writeSparseTypeCode(offset, this.layoutCode());
int lenInBytes = LayoutCode.BYTES;
for (int i = 1; i < value.count(); i++) {
TypeArgument arg = value.get(i);
lenInBytes += arg.type().writeTypeArgument(row, offset + lenInBytes, arg.typeArgs());
lenInBytes += arg.type().writeTypeArgument(buffer, offset + lenInBytes, arg.typeArgs());
}
return lenInBytes;

View File

@@ -4,13 +4,15 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out;
import com.azure.data.cosmos.core.Reference;
import com.azure.data.cosmos.serialization.hybridrow.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull;
import static com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.IMMUTABLE_TUPLE_SCOPE;
import static com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.TUPLE_SCOPE;
import static com.google.common.base.Preconditions.checkNotNull;
public final class LayoutTuple extends LayoutIndexedScope {
@@ -21,47 +23,46 @@ public final class LayoutTuple extends LayoutIndexedScope {
);
}
@Override
public int countTypeArgument(@Nonnull final TypeArgumentList value) {
checkNotNull(value, "expected non-null value");
return value.stream()
.map(arg -> arg.type().countTypeArgument(arg.typeArgs()))
.reduce(LayoutCode.BYTES + RowBuffer.count7BitEncodedUInt(value.count()), Integer::sum);
}
@Override
@Nonnull
public String name() {
return this.isImmutable() ? "im_tuple" : "tuple";
}
public int countTypeArgument(TypeArgumentList value) {
int lenInBytes = LayoutCode.BYTES;
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: lenInBytes += RowBuffer.Count7BitEncodedUInt((ulong)value.Count);
lenInBytes += RowBuffer.count7BitEncodedUInt(value.count());
for (TypeArgument arg : value) {
lenInBytes += arg.type().countTypeArgument(arg.typeArgs());
}
return lenInBytes;
}
@Override
@Nonnull
public TypeArgumentList readTypeArgumentList(RowBuffer buffer, int offset, Out<Integer> lenInBytes) {
int numTypeArgs = buffer.intValue().Read7BitEncodedUInt(offset, lenInBytes);
TypeArgument[] retval = new TypeArgument[numTypeArgs];
final int numTypeArgs = buffer.read7BitEncodedUInt(offset, lenInBytes);
final TypeArgument[] typeArgs = new TypeArgument[numTypeArgs];
final Out<Integer> itemLength = new Out<>();
for (int i = 0; i < numTypeArgs; i++) {
int itemLenInBytes;
Out<Integer> tempOut_itemLenInBytes = new Out<Integer>();
retval[i] = readTypeArgument(buffer, offset + lenInBytes.get(), tempOut_itemLenInBytes);
itemLenInBytes = tempOut_itemLenInBytes.get();
lenInBytes.set(lenInBytes.get() + itemLenInBytes);
typeArgs[i] = readTypeArgument(buffer, offset + lenInBytes.get(), itemLength);
lenInBytes.set(lenInBytes.get() + itemLength.get());
}
return new TypeArgumentList(retval);
return new TypeArgumentList(typeArgs);
}
@Override
@Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, Out<RowCursor> value) {
return writeScope(buffer, edit, typeArgs, UpdateOptions.Upsert, value);
return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value);
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public override Result WriteScope(ref RowBuffer b, ref RowCursor edit, TypeArgumentList
// typeArgs, out RowCursor value, UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, UpdateOptions options, Out<RowCursor> value) {
@Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, UpdateOptions options,
Out<RowCursor> value) {
Result result = prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs), options);

View File

@@ -11,6 +11,7 @@ import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Strings.lenientFormat;
/**
@@ -23,7 +24,7 @@ import static com.google.common.base.Strings.lenientFormat;
*/
public abstract class LayoutType<T> implements ILayoutType {
private static final LayoutType[] CodeIndex = new LayoutType[LayoutCode.END_SCOPE.value() + 1];
private static final LayoutType[] codeIndex = new LayoutType[LayoutCode.END_SCOPE.value() + 1];
private final boolean immutable;
private final LayoutCode layoutCode;
@@ -33,12 +34,16 @@ public abstract class LayoutType<T> implements ILayoutType {
/**
* Initializes a new instance of the {@link LayoutType<T>} class.
*/
protected LayoutType(LayoutCode code, boolean immutable, int size) {
protected LayoutType(@Nonnull final LayoutCode code, final boolean immutable, final int size) {
checkNotNull(code, "expected non-null code");
this.layoutCode = code;
this.immutable = immutable;
this.size = size;
this.typeArg = new TypeArgument(this);
CodeIndex[code.value()] = this;
codeIndex[code.value()] = this;
}
/**
@@ -89,11 +94,12 @@ public abstract class LayoutType<T> implements ILayoutType {
return !this.isFixed();
}
public int countTypeArgument(TypeArgumentList value) {
public int countTypeArgument(@Nonnull TypeArgumentList value) {
return LayoutCode.BYTES;
}
public final Result deleteFixed(RowBuffer b, RowCursor scope, LayoutColumn column) {
@Nonnull
public final Result deleteFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -106,7 +112,7 @@ public abstract class LayoutType<T> implements ILayoutType {
return Result.TYPE_MISMATCH;
}
b.unsetBit(scope.start(), column.nullBit());
buffer.unsetBit(scope.start(), column.nullBit());
return Result.SUCCESS;
}
@@ -115,18 +121,19 @@ public abstract class LayoutType<T> implements ILayoutType {
* <p>
* If a value exists, then it is removed. The remainder of the row is resized to accomodate
* a decrease in required space. If no value exists this operation is a no-op.
* @param b
* @param buffer
* @param edit
*/
public final Result deleteSparse(RowBuffer b, RowCursor edit) {
@Nonnull
public final Result deleteSparse(RowBuffer buffer, RowCursor edit) {
Result result = LayoutType.prepareSparseDelete(b, edit, this.layoutCode());
Result result = LayoutType.prepareSparseDelete(buffer, edit, this.layoutCode());
if (result != Result.SUCCESS) {
return result;
}
b.deleteSparse(edit);
buffer.deleteSparse(edit);
return Result.SUCCESS;
}
@@ -136,7 +143,8 @@ public abstract class LayoutType<T> implements ILayoutType {
* If a value exists, then it is removed. The remainder of the row is resized to accommodate a decrease in
* required space. If no value exists this operation is a no-op.
*/
public final Result deleteVariable(RowBuffer b, RowCursor scope, LayoutColumn column) {
@Nonnull
public final Result deleteVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -144,25 +152,27 @@ public abstract class LayoutType<T> implements ILayoutType {
return Result.INSUFFICIENT_PERMISSIONS;
}
boolean exists = b.readBit(scope.start(), column.nullBit());
boolean exists = buffer.readBit(scope.start(), column.nullBit());
if (exists) {
int varOffset = b.computeVariableValueOffset(scope.layout(), scope.start(), column.offset());
b.deleteVariable(varOffset, this.isVarint());
b.unsetBit(scope.start(), column.nullBit());
int varOffset = buffer.computeVariableValueOffset(scope.layout(), scope.start(), column.offset());
buffer.deleteVariable(varOffset, this.isVarint());
buffer.unsetBit(scope.start(), column.nullBit());
}
return Result.SUCCESS;
}
@Nonnull
public static LayoutType fromCode(LayoutCode code) {
LayoutType type = LayoutType.CodeIndex[code.value()];
LayoutType type = LayoutType.codeIndex[code.value()];
assert type != null : lenientFormat("Not Implemented: %s", code);
return type;
}
public final Result hasValue(RowBuffer b, RowCursor scope, LayoutColumn column) {
if (!b.readBit(scope.start(), column.nullBit())) {
@Nonnull
public final Result hasValue(RowBuffer buffer, RowCursor scope, LayoutColumn column) {
if (!buffer.readBit(scope.start(), column.nullBit())) {
return Result.NOT_FOUND;
}
return Result.SUCCESS;
@@ -171,6 +181,7 @@ public abstract class LayoutType<T> implements ILayoutType {
/**
* The physical layout code used to represent the type within the serialization.
*/
@Nonnull
public LayoutCode layoutCode() {
return this.layoutCode;
}
@@ -178,17 +189,19 @@ public abstract class LayoutType<T> implements ILayoutType {
/**
* Human readable name of the type.
*/
@Nonnull
public abstract String name();
/**
* Helper for preparing the delete of a sparse field.
*
* @param b The row to delete from.
* @param buffer The row to delete from.
* @param edit The parent edit containing the field to delete.
* @param code The expected type of the field.
* @return Success if the delete is permitted, the error code otherwise.
*/
public static Result prepareSparseDelete(RowBuffer b, RowCursor edit, LayoutCode code) {
@Nonnull
public static Result prepareSparseDelete(RowBuffer buffer, RowCursor edit, LayoutCode code) {
if (edit.scopeType().isFixedArity()) {
return Result.TYPE_CONSTRAINT;
@@ -226,8 +239,8 @@ public abstract class LayoutType<T> implements ILayoutType {
TypeArgument elementType,
RowCursor srcEdit,
UpdateOptions options,
Out<RowCursor> dstEdit
) {
Out<RowCursor> dstEdit) {
checkArgument(destinationScope.scopeType() == destinationCode);
checkArgument(destinationScope.index() == 0, "Can only insert into a edit at the root");
@@ -235,44 +248,45 @@ public abstract class LayoutType<T> implements ILayoutType {
Result result = LayoutType.prepareSparseDelete(buffer, srcEdit, elementType.type().layoutCode());
if (result != Result.SUCCESS) {
dstEdit.setAndGet(null);
dstEdit.set(null);
return result;
}
if (!srcEdit.exists()) {
dstEdit.setAndGet(null);
dstEdit.set(null);
return Result.NOT_FOUND;
}
if (destinationScope.immutable()) {
buffer.deleteSparse(srcEdit);
dstEdit.setAndGet(null);
dstEdit.set(null);
return Result.INSUFFICIENT_PERMISSIONS;
}
if (!srcEdit.cellTypeArgs().equals(elementType.typeArgs())) {
buffer.deleteSparse(srcEdit);
dstEdit.setAndGet(null);
dstEdit.set(null);
return Result.TYPE_CONSTRAINT;
}
if (options == UpdateOptions.InsertAt) {
if (options == UpdateOptions.INSERT_AT) {
buffer.deleteSparse(srcEdit);
dstEdit.setAndGet(null);
dstEdit.set(null);
return Result.TYPE_CONSTRAINT;
}
// Prepare the insertion at the destination.
dstEdit.setAndGet(buffer.prepareSparseMove(destinationScope, srcEdit));
if ((options == UpdateOptions.Update) && (!dstEdit.get().exists())) {
dstEdit.set(buffer.prepareSparseMove(destinationScope, srcEdit));
if ((options == UpdateOptions.UPDATE) && (!dstEdit.get().exists())) {
buffer.deleteSparse(srcEdit);
dstEdit.setAndGet(null);
dstEdit.set(null);
return Result.NOT_FOUND;
}
if ((options == UpdateOptions.Insert) && dstEdit.get().exists()) {
if ((options == UpdateOptions.INSERT) && dstEdit.get().exists()) {
buffer.deleteSparse(srcEdit);
dstEdit.setAndGet(null);
dstEdit.set(null);
return Result.EXISTS;
}
@@ -334,19 +348,19 @@ public abstract class LayoutType<T> implements ILayoutType {
return Result.TYPE_CONSTRAINT;
}
if ((options == UpdateOptions.InsertAt) && edit.scopeType().isFixedArity()) {
if ((options == UpdateOptions.INSERT_AT) && edit.scopeType().isFixedArity()) {
return Result.TYPE_CONSTRAINT;
}
if ((options == UpdateOptions.InsertAt) && !edit.scopeType().isFixedArity()) {
if ((options == UpdateOptions.INSERT_AT) && !edit.scopeType().isFixedArity()) {
edit.exists(false); // InsertAt never overwrites an existing item.
}
if ((options == UpdateOptions.Update) && (!edit.exists())) {
if ((options == UpdateOptions.UPDATE) && (!edit.exists())) {
return Result.NOT_FOUND;
}
if ((options == UpdateOptions.Insert) && edit.exists()) {
if ((options == UpdateOptions.INSERT) && edit.exists()) {
return Result.EXISTS;
}
@@ -359,23 +373,45 @@ public abstract class LayoutType<T> implements ILayoutType {
@Nonnull
public abstract Result readSparse(RowBuffer buffer, RowCursor edit, Out<T> value);
public static TypeArgument readTypeArgument(RowBuffer row, int offset, Out<Integer> lenInBytes) {
LayoutType itemCode = row.readSparseTypeCode(offset);
int argsLenInBytes;
Out<Integer> tempOut_argsLenInBytes = new Out<>();
TypeArgumentList itemTypeArgs = itemCode.readTypeArgumentList(row, offset + LayoutCode.BYTES, tempOut_argsLenInBytes);
argsLenInBytes = tempOut_argsLenInBytes.get();
lenInBytes.setAndGet(LayoutCode.BYTES + argsLenInBytes);
return new TypeArgument(itemCode, itemTypeArgs);
@Nonnull
public static TypeArgument readTypeArgument(
@Nonnull final RowBuffer buffer, final int offset, @Nonnull final Out<Integer> lengthInBytes) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(lengthInBytes, "expected non-null lengthInBytes");
checkArgument(offset >= 0, "expected non-negative offset, not %s", offset);
LayoutType type = buffer.readSparseTypeCode(offset);
TypeArgumentList typeArgs = type.readTypeArgumentList(buffer, offset + LayoutCode.BYTES, lengthInBytes);
lengthInBytes.set(LayoutCode.BYTES + lengthInBytes.get());
return new TypeArgument(type, typeArgs);
}
public TypeArgumentList readTypeArgumentList(RowBuffer row, int offset, Out<Integer> lenInBytes) {
lenInBytes.setAndGet(0);
@Nonnull
public TypeArgumentList readTypeArgumentList(
@Nonnull final RowBuffer buffer, final int offset, @Nonnull final Out<Integer> lengthInBytes) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(lengthInBytes, "expected non-null lengthInBytes");
checkArgument(offset >= 0, "expected non-negative offset, not %s", offset);
lengthInBytes.set(0);
return TypeArgumentList.EMPTY;
}
@Nonnull
public Result readVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<T> value) {
public Result readVariable(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor scope,
@Nonnull final LayoutColumn column,
@Nonnull final Out<T> value) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(scope, "expected non-null scope");
checkNotNull(column, "expected non-null column");
checkNotNull(value, "expected non-null value");
value.set(null);
return Result.FAILURE;
}
@@ -404,8 +440,8 @@ public abstract class LayoutType<T> implements ILayoutType {
@Nonnull
public abstract Result writeSparse(RowBuffer buffer, RowCursor edit, T value, UpdateOptions options);
public int writeTypeArgument(RowBuffer row, int offset, TypeArgumentList value) {
row.writeSparseTypeCode(offset, this.layoutCode());
public int writeTypeArgument(RowBuffer buffer, int offset, TypeArgumentList value) {
buffer.writeSparseTypeCode(offset, this.layoutCode());
return LayoutCode.BYTES;
}

View File

@@ -4,74 +4,96 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out;
import com.azure.data.cosmos.core.Reference;
import com.azure.data.cosmos.serialization.hybridrow.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
public final class LayoutTypedArray extends LayoutIndexedScope {
public LayoutTypedArray(boolean immutable) {
super(immutable ? com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.IMMUTABLE_TYPED_ARRAY_SCOPE :
com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.TYPED_ARRAY_SCOPE, immutable, true, false, false, true);
}
public String name() {
return this.Immutable ? "im_array_t" : "array_t";
}
public int countTypeArgument(TypeArgumentList value) {
@Override
public int countTypeArgument(@Nonnull TypeArgumentList value) {
checkNotNull(value, "expected non-null value");
checkState(value.count() == 1);
return (com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE) + value.get(0).type().CountTypeArgument(value.get(0).typeArgs().clone());
return LayoutCode.BYTES + value.get(0).type().countTypeArgument(value.get(0).typeArgs());
}
@Override
public boolean HasImplicitTypeCode(Reference<RowCursor> edit) {
checkState(edit.get().index() >= 0);
checkState(edit.get().scopeTypeArgs().count() == 1);
return !LayoutCodeTraits.alwaysRequiresTypeCode(edit.get().scopeTypeArgs().get(0).type().LayoutCode);
public boolean hasImplicitTypeCode(RowCursor edit) {
checkState(edit.index() >= 0);
checkState(edit.scopeTypeArgs().count() == 1);
return !LayoutCodeTraits.alwaysRequiresTypeCode(edit.scopeTypeArgs().get(0).type().layoutCode());
}
@Override
public TypeArgumentList readTypeArgumentList(Reference<RowBuffer> row, int offset,
Out<Integer> lenInBytes) {
return new TypeArgumentList(new TypeArgument[] { LayoutType.readTypeArgument(row, offset, lenInBytes) });
@Nonnull
public String name() {
return this.isImmutable() ? "im_array_t" : "array_t";
}
@Override
public void setImplicitTypeCode(RowCursor edit) {
edit.get().cellType = edit.get().scopeTypeArgs().get(0).type();
edit.get().cellTypeArgs = edit.get().scopeTypeArgs().get(0).typeArgs().clone();
@Nonnull
public TypeArgumentList readTypeArgumentList(RowBuffer buffer, int offset, Out<Integer> lenInBytes) {
return new TypeArgumentList(LayoutType.readTypeArgument(buffer, offset, lenInBytes));
}
@Override
public Result writeScope(RowBuffer buffer, RowCursor edit,
TypeArgumentList typeArgs, Out<RowCursor> value) {
return writeScope(buffer, edit, typeArgs, UpdateOptions.Upsert, value);
public void setImplicitTypeCode(@Nonnull final RowCursor edit) {
edit.cellType(edit.scopeTypeArgs().get(0).type());
edit.cellTypeArgs(edit.scopeTypeArgs().get(0).typeArgs());
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public override Result WriteScope(ref RowBuffer b, ref RowCursor edit, TypeArgumentList
// typeArgs, out RowCursor value, UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result writeScope(RowBuffer buffer, RowCursor edit,
TypeArgumentList typeArgs, UpdateOptions options, Out<RowCursor> value) {
Result result = LayoutType.prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs.clone()), options);
@Nonnull
public Result writeScope(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor edit,
@Nonnull final TypeArgumentList typeArgs,
@Nonnull final Out<RowCursor> value) {
return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value);
}
@Override
@Nonnull
public Result writeScope(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor edit,
@Nonnull final TypeArgumentList typeArgs,
@Nonnull final UpdateOptions options,
@Nonnull final Out<RowCursor> value) {
final TypeArgument typeArg = new TypeArgument(this, typeArgs);
final Result result = LayoutType.prepareSparseWrite(buffer, edit, typeArg, options);
if (result != Result.SUCCESS) {
value.setAndGet(null);
value.set(null);
return result;
}
buffer.get().WriteTypedArray(edit, this, typeArgs.clone(), options, value.clone());
value.set(buffer.writeTypedArray(edit, this, typeArgs, options));
return Result.SUCCESS;
}
@Override
public int writeTypeArgument(Reference<RowBuffer> row, int offset, TypeArgumentList value) {
public int writeTypeArgument(
@Nonnull final RowBuffer buffer, final int offset, @Nonnull final TypeArgumentList value) {
checkState(value.count() == 1);
row.get().writeSparseTypeCode(offset, this.LayoutCode);
int lenInBytes = (com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE);
lenInBytes += value.get(0).type().writeTypeArgument(row, offset + lenInBytes,
value.get(0).typeArgs().clone());
return lenInBytes;
TypeArgument typeArg = value.get(0);
buffer.writeSparseTypeCode(offset, this.layoutCode());
return LayoutCode.BYTES + typeArg.type().writeTypeArgument(
buffer, offset + LayoutCode.BYTES, typeArg.typeArgs()
);
}
}

View File

@@ -4,11 +4,15 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out;
import com.azure.data.cosmos.core.Reference;
import com.azure.data.cosmos.serialization.hybridrow.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
public final class LayoutTypedMap extends LayoutUniqueScope {
public LayoutTypedMap(boolean immutable) {
super(immutable ? com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.IMMUTABLE_TYPED_MAP_SCOPE :
@@ -16,42 +20,44 @@ public final class LayoutTypedMap extends LayoutUniqueScope {
true, isTypedScope():true)
}
public String name() {
return this.Immutable ? "im_map_t" : "map_t";
}
public int countTypeArgument(TypeArgumentList value) {
@Override
public int countTypeArgument(@Nonnull TypeArgumentList value) {
checkNotNull(value, "expected non-null value");
checkState(value.count() == 2);
int lenInBytes = (com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE);
for (TypeArgument arg : value) {
lenInBytes += arg.type().CountTypeArgument(arg.typeArgs().clone());
}
return lenInBytes;
return value.stream()
.map(arg -> arg.type().countTypeArgument(arg.typeArgs()))
.reduce(LayoutCode.BYTES, Integer::sum);
}
@Nonnull
@Override
public TypeArgument fieldType(RowCursor scope) {
return new TypeArgument(scope.get().scopeType().Immutable ? ImmutableTypedTuple :
TypedTuple, scope.get().scopeTypeArgs().clone());
return new TypeArgument(
scope.scopeType().isImmutable() ? LayoutTypes.IMMUTABLE_TYPED_TUPLE : LayoutTypes.TYPED_TUPLE,
scope.scopeTypeArgs());
}
@Override
public boolean HasImplicitTypeCode(Reference<RowCursor> edit) {
public boolean hasImplicitTypeCode(RowCursor edit) {
return true;
}
@Nonnull
public String name() {
return this.isImmutable() ? "im_map_t" : "map_t";
}
@Override
public TypeArgumentList readTypeArgumentList(Reference<RowBuffer> row, int offset,
public TypeArgumentList readTypeArgumentList(RowBuffer row, int offset,
Out<Integer> lenInBytes) {
lenInBytes.setAndGet(0);
TypeArgument[] retval = new TypeArgument[2];
for (int i = 0; i < 2; i++) {
int itemLenInBytes;
Out<Integer> tempOut_itemLenInBytes = new Out<Integer>();
retval[i] = readTypeArgument(row, offset + lenInBytes.get(), tempOut_itemLenInBytes);
itemLenInBytes = tempOut_itemLenInBytes.get();
lenInBytes.setAndGet(lenInBytes.get() + itemLenInBytes);
retval[i] = readTypeArgument(row, offset + lenInBytes, tempOut_itemLenInBytes);
itemLenInBytes = tempOut_itemLenInBytes;
lenInBytes.setAndGet(lenInBytes + itemLenInBytes);
}
return new TypeArgumentList(retval);
@@ -59,40 +65,39 @@ public final class LayoutTypedMap extends LayoutUniqueScope {
@Override
public void setImplicitTypeCode(RowCursor edit) {
edit.get().cellType = edit.get().scopeType().Immutable ? ImmutableTypedTuple :
TypedTuple;
edit.get().cellTypeArgs = edit.get().scopeTypeArgs().clone();
edit.cellType(edit.scopeType().isImmutable() ? LayoutTypes.IMMUTABLE_TYPED_TUPLE : LayoutTypes.TYPED_TUPLE);
edit.cellTypeArgs(edit.scopeTypeArgs());
}
@Override
public Result writeScope(RowBuffer buffer, RowCursor edit,
TypeArgumentList typeArgs, Out<RowCursor> value) {
return writeScope(buffer, edit, typeArgs, UpdateOptions.Upsert, value);
@Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, Out<RowCursor> value) {
return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value);
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public override Result WriteScope(ref RowBuffer b, ref RowCursor edit, TypeArgumentList
// typeArgs, out RowCursor value, UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result writeScope(RowBuffer buffer, RowCursor edit,
TypeArgumentList typeArgs, UpdateOptions options, Out<RowCursor> value) {
Result result = prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs.clone()), options);
@Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, UpdateOptions options,
Out<RowCursor> value) {
Result result = prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs), options);
if (result != Result.SUCCESS) {
value.setAndGet(null);
return result;
}
buffer.get().WriteTypedMap(edit, this, typeArgs.clone(), options, value.clone());
value.set(buffer.writeTypedMap(edit, this, typeArgs, options));
return Result.SUCCESS;
}
@Override
public int writeTypeArgument(Reference<RowBuffer> row, int offset, TypeArgumentList value) {
public int writeTypeArgument(RowBuffer buffer, int offset, TypeArgumentList value) {
checkState(value.count() == 2);
row.get().writeSparseTypeCode(offset, this.LayoutCode);
int lenInBytes = (com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE);
buffer.writeSparseTypeCode(offset, this.layoutCode());
int lenInBytes = LayoutCode.BYTES;
for (TypeArgument arg : value) {
lenInBytes += arg.type().writeTypeArgument(row, offset + lenInBytes, arg.typeArgs().clone());
lenInBytes += arg.type().writeTypeArgument(buffer, offset + lenInBytes, arg.typeArgs());
}
return lenInBytes;

View File

@@ -4,81 +4,92 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out;
import com.azure.data.cosmos.core.Reference;
import com.azure.data.cosmos.serialization.hybridrow.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull;
import static com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.IMMUTABLE_TYPED_SET_SCOPE;
import static com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.TYPED_SET_SCOPE;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
public final class LayoutTypedSet extends LayoutUniqueScope {
public LayoutTypedSet(boolean immutable) {
super(immutable ? IMMUTABLE_TYPED_SET_SCOPE : TYPED_SET_SCOPE, immutable, true, true);
}
public String name() {
return this.Immutable ? "im_set_t" : "set_t";
}
public int countTypeArgument(TypeArgumentList value) {
@Override
public int countTypeArgument(@Nonnull TypeArgumentList value) {
checkNotNull(value, "expected non-null value");
checkState(value.count() == 1);
return (com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE) + value.get(0).type().CountTypeArgument(value.get(0).typeArgs().clone());
return LayoutCode.BYTES + value.get(0).type().countTypeArgument(value.get(0).typeArgs());
}
@Nonnull
@Override
public TypeArgument fieldType(RowCursor scope) {
return scope.get().scopeTypeArgs().get(0).clone();
return scope.scopeTypeArgs().get(0);
}
@Override
public boolean HasImplicitTypeCode(Reference<RowCursor> edit) {
checkState(edit.get().index() >= 0);
checkState(edit.get().scopeTypeArgs().count() == 1);
return !LayoutCodeTraits.alwaysRequiresTypeCode(edit.get().scopeTypeArgs().get(0).type().LayoutCode);
public boolean hasImplicitTypeCode(RowCursor edit) {
checkState(edit.index() >= 0);
checkState(edit.scopeTypeArgs().count() == 1);
return !LayoutCodeTraits.alwaysRequiresTypeCode(edit.scopeTypeArgs().get(0).type().layoutCode());
}
@Nonnull
public String name() {
return this.isImmutable() ? "im_set_t" : "set_t";
}
@Override
public TypeArgumentList readTypeArgumentList(Reference<RowBuffer> row, int offset,
Out<Integer> lenInBytes) {
return new TypeArgumentList(new TypeArgument[] { readTypeArgument(row, offset, lenInBytes) });
@Nonnull
public TypeArgumentList readTypeArgumentList(RowBuffer buffer, int offset, Out<Integer> lenInBytes) {
return new TypeArgumentList(readTypeArgument(buffer, offset, lenInBytes));
}
@Override
public void setImplicitTypeCode(RowCursor edit) {
edit.get().cellType = edit.get().scopeTypeArgs().get(0).type();
edit.get().cellTypeArgs = edit.get().scopeTypeArgs().get(0).typeArgs().clone();
edit.cellType(edit.scopeTypeArgs().get(0).type());
edit.cellTypeArgs(edit.scopeTypeArgs().get(0).typeArgs());
}
@Override
@Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit,
TypeArgumentList typeArgs, Out<RowCursor> value) {
return writeScope(buffer, edit, typeArgs, UpdateOptions.Upsert, value);
return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value);
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public override Result WriteScope(ref RowBuffer b, ref RowCursor edit, TypeArgumentList
// typeArgs, out RowCursor value, UpdateOptions options = UpdateOptions.Upsert)
@Override
@Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit,
TypeArgumentList typeArgs, UpdateOptions options, Out<RowCursor> value) {
Result result = prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs.clone()), options);
Result result = prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs), options);
if (result != Result.SUCCESS) {
value.setAndGet(null);
return result;
}
buffer.get().WriteTypedSet(edit, this, typeArgs.clone(), options, value.clone());
buffer.writeTypedSet(edit, this, typeArgs, options, value);
return Result.SUCCESS;
}
@Override
public int writeTypeArgument(Reference<RowBuffer> row, int offset, TypeArgumentList value) {
public int writeTypeArgument(RowBuffer buffer, int offset, TypeArgumentList value) {
checkArgument(value.count() == 1);
row.get().writeSparseTypeCode(offset, this.LayoutCode);
int lenInBytes = (com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE);
lenInBytes += value.get(0).type().writeTypeArgument(row, offset + lenInBytes,
value.get(0).typeArgs().clone());
buffer.writeSparseTypeCode(offset, this.layoutCode());
int lenInBytes = LayoutCode.BYTES;
lenInBytes += value.get(0).type().writeTypeArgument(buffer, offset + lenInBytes,
value.get(0).typeArgs());
return lenInBytes;
}
}

View File

@@ -4,95 +4,100 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out;
import com.azure.data.cosmos.core.Reference;
import com.azure.data.cosmos.serialization.hybridrow.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
public final class LayoutTypedTuple extends LayoutIndexedScope {
public LayoutTypedTuple(boolean immutable) {
super(immutable ? com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.IMMUTABLE_TYPED_TUPLE_SCOPE :
com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.TYPED_TUPLE_SCOPE, immutable, true, true, false, true);
super(
immutable ? LayoutCode.IMMUTABLE_TYPED_TUPLE_SCOPE : LayoutCode.TYPED_TUPLE_SCOPE, immutable,
true, true, false, true
);
}
@Override
public int countTypeArgument(@Nonnull TypeArgumentList value) {
checkNotNull(value, "expected non-null value");
return value.stream()
.map(arg -> arg.type().countTypeArgument(arg.typeArgs()))
.reduce(LayoutCode.BYTES + RowBuffer.count7BitEncodedUInt(value.count()), Integer::sum);
}
@Override
public boolean hasImplicitTypeCode(RowCursor edit) {
checkArgument(edit.index() >= 0);
checkArgument(edit.scopeTypeArgs().count() > edit.index());
return !LayoutCodeTraits.alwaysRequiresTypeCode(edit.scopeTypeArgs().get(edit.index()).type().layoutCode());
}
@Override
@Nonnull
public String name() {
return this.Immutable ? "im_tuple_t" : "tuple_t";
}
public int countTypeArgument(TypeArgumentList value) {
int lenInBytes = (com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE);
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: lenInBytes += RowBuffer.Count7BitEncodedUInt((ulong)value.Count);
lenInBytes += RowBuffer.count7BitEncodedUInt(value.count());
for (TypeArgument arg : value) {
lenInBytes += arg.type().CountTypeArgument(arg.typeArgs().clone());
}
return lenInBytes;
return this.isImmutable() ? "im_tuple_t" : "tuple_t";
}
@Override
public boolean HasImplicitTypeCode(Reference<RowCursor> edit) {
checkArgument(edit.get().index() >= 0);
checkArgument(edit.get().scopeTypeArgs().count() > edit.get().index());
return !LayoutCodeTraits.alwaysRequiresTypeCode(edit.get().scopeTypeArgs().get(edit.get().index()).type().LayoutCode);
}
public TypeArgumentList readTypeArgumentList(RowBuffer row, int offset, Out<Integer> lenInBytes) {
int numTypeArgs = row.read7BitEncodedUInt(offset, lenInBytes);
TypeArgument[] typeArgs = new TypeArgument[numTypeArgs];
@Override
public TypeArgumentList readTypeArgumentList(Reference<RowBuffer> row, int offset,
Out<Integer> lenInBytes) {
int numTypeArgs = row.get().intValue().Read7BitEncodedUInt(offset, lenInBytes);
TypeArgument[] retval = new TypeArgument[numTypeArgs];
for (int i = 0; i < numTypeArgs; i++) {
int itemLenInBytes;
Out<Integer> tempOut_itemLenInBytes = new Out<Integer>();
retval[i] = LayoutType.readTypeArgument(row, offset + lenInBytes.get(), tempOut_itemLenInBytes);
itemLenInBytes = tempOut_itemLenInBytes.get();
lenInBytes.setAndGet(lenInBytes.get() + itemLenInBytes);
typeArgs[i] = LayoutType.readTypeArgument(row, offset + lenInBytes, tempOut_itemLenInBytes);
itemLenInBytes = tempOut_itemLenInBytes;
lenInBytes.setAndGet(lenInBytes + itemLenInBytes);
}
return new TypeArgumentList(retval);
return new TypeArgumentList(typeArgs);
}
@Override
public void setImplicitTypeCode(RowCursor edit) {
edit.get().cellType = edit.get().scopeTypeArgs().get(edit.get().index()).type();
edit.get().cellTypeArgs = edit.get().scopeTypeArgs().get(edit.get().index()).typeArgs().clone();
edit.cellType(edit.scopeTypeArgs().get(edit.index()).type());
edit.cellTypeArgs(edit.scopeTypeArgs().get(edit.index()).typeArgs());
}
@Override
@Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit,
TypeArgumentList typeArgs, Out<RowCursor> value) {
return writeScope(buffer, edit, typeArgs, UpdateOptions.Upsert, value);
return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value);
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public override Result WriteScope(ref RowBuffer b, ref RowCursor edit, TypeArgumentList
// typeArgs, out RowCursor value, UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result writeScope(RowBuffer buffer, RowCursor edit,
TypeArgumentList typeArgs, UpdateOptions options, Out<RowCursor> value) {
Result result = LayoutType.prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs.clone()), options);
@Nonnull
public Result writeScope(
RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, UpdateOptions options, Out<RowCursor> value) {
Result result = LayoutType.prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs), options);
if (result != Result.SUCCESS) {
value.setAndGet(null);
return result;
}
buffer.get().WriteTypedTuple(edit, this, typeArgs.clone(), options, value.clone());
value.set(buffer.writeTypedTuple(edit, this, typeArgs, options));
return Result.SUCCESS;
}
@Override
public int writeTypeArgument(Reference<RowBuffer> row, int offset, TypeArgumentList value) {
row.get().writeSparseTypeCode(offset, this.LayoutCode);
int lenInBytes = (com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE);
public int writeTypeArgument(RowBuffer buffer, int offset, TypeArgumentList value) {
buffer.writeSparseTypeCode(offset, this.layoutCode());
int lenInBytes = LayoutCode.BYTES;
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: lenInBytes += row.Write7BitEncodedUInt(offset + lenInBytes, (ulong)value.Count);
lenInBytes += row.get().write7BitEncodedUInt(offset + lenInBytes, value.count());
lenInBytes += buffer.write7BitEncodedUInt(offset + lenInBytes, value.count());
for (TypeArgument arg : value) {
lenInBytes += arg.type().writeTypeArgument(row, offset + lenInBytes, arg.typeArgs().clone());
lenInBytes += arg.type().writeTypeArgument(buffer, offset + lenInBytes, arg.typeArgs());
}
return lenInBytes;

View File

@@ -4,61 +4,68 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out;
import com.azure.data.cosmos.core.Reference;
import com.azure.data.cosmos.serialization.hybridrow.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import com.azure.data.cosmos.serialization.hybridrow.SchemaId;
import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkNotNull;
public final class LayoutUDT extends LayoutPropertyScope {
public LayoutUDT(boolean immutable) {
super(immutable ? com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.IMMUTABLE_SCHEMA :
com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SCHEMA, immutable);
super(immutable ? LayoutCode.IMMUTABLE_SCHEMA : LayoutCode.SCHEMA, immutable);
}
@Override
public int countTypeArgument(@Nonnull TypeArgumentList value) {
checkNotNull(value, "expected non-null value");
return LayoutCode.BYTES + SchemaId.BYTES;
}
@Override
@Nonnull
public String name() {
return this.Immutable ? "im_udt" : "udt";
}
public int countTypeArgument(TypeArgumentList value) {
return (com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE) + SchemaId.BYTES;
return this.isImmutable() ? "im_udt" : "udt";
}
@Override
public TypeArgumentList readTypeArgumentList(Reference<RowBuffer> row, int offset,
Out<Integer> lenInBytes) {
SchemaId schemaId = row.get().readSchemaId(offset).clone();
lenInBytes.setAndGet(SchemaId.BYTES);
return new TypeArgumentList(schemaId.clone());
@Nonnull
public TypeArgumentList readTypeArgumentList(RowBuffer row, int offset, Out<Integer> lenInBytes) {
SchemaId schemaId = row.readSchemaId(offset);
lenInBytes.set(SchemaId.BYTES);
return new TypeArgumentList(schemaId);
}
@Override
public Result writeScope(RowBuffer buffer, RowCursor edit,
TypeArgumentList typeArgs, Out<RowCursor> value) {
return writeScope(buffer, edit, typeArgs, UpdateOptions.Upsert, value);
@Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, Out<RowCursor> value) {
return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value);
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public override Result WriteScope(ref RowBuffer b, ref RowCursor edit, TypeArgumentList
// typeArgs, out RowCursor value, UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result writeScope(RowBuffer buffer, RowCursor edit,
TypeArgumentList typeArgs, UpdateOptions options, Out<RowCursor> value) {
Layout udt = buffer.get().resolver().resolve(typeArgs.schemaId().clone());
Result result = prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs.clone()), options);
@Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, UpdateOptions options,
Out<RowCursor> value) {
Layout udt = buffer.resolver().resolve(typeArgs.schemaId());
Result result = prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs), options);
if (result != Result.SUCCESS) {
value.setAndGet(null);
value.set(null);
return result;
}
buffer.get().WriteSparseUDT(edit, this, udt, options, value.clone());
value.set(buffer.writeSparseUDT(edit, this, udt, options));
return Result.SUCCESS;
}
@Override
public int writeTypeArgument(Reference<RowBuffer> row, int offset, TypeArgumentList value) {
row.get().writeSparseTypeCode(offset, this.LayoutCode);
row.get().writeSchemaId(offset + (com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE), value.schemaId().clone());
return (com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE) + SchemaId.BYTES;
public int writeTypeArgument(RowBuffer buffer, int offset, TypeArgumentList value) {
buffer.writeSparseTypeCode(offset, this.layoutCode());
buffer.writeSchemaId(offset + LayoutCode.BYTES, value.schemaId());
return LayoutCode.BYTES + SchemaId.BYTES;
}
}

View File

@@ -4,93 +4,91 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out;
import com.azure.data.cosmos.core.Reference;
import com.azure.data.cosmos.serialization.hybridrow.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument;
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public sealed class LayoutUInt16 : LayoutType<ushort>
public final class LayoutUInt16 extends LayoutType<Short> {
public final class LayoutUInt16 extends LayoutType<Integer> {
public LayoutUInt16() {
super(com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.UINT_16, (Short.SIZE / Byte.SIZE));
super(LayoutCode.UINT_16, Short.BYTES);
}
public boolean isFixed() {
return true;
}
@Nonnull
public String name() {
return "uint16";
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public override Result ReadFixed(ref RowBuffer b, ref RowCursor scope, LayoutColumn col, out
// ushort value)
@Override
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column,
Out<Short> value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT);
if (!buffer.get().readBit(scope.get().start(), column.getNullBit().clone())) {
value.setAndGet(0);
@Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Integer> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
if (!buffer.readBit(scope.start(), column.nullBit())) {
value.set(0);
return Result.NOT_FOUND;
}
value.setAndGet(buffer.get().ReadUInt16(scope.get().start() + column.getOffset()));
value.set(buffer.readUInt16(scope.start() + column.offset()));
return Result.SUCCESS;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public override Result ReadSparse(ref RowBuffer b, ref RowCursor edit, out ushort value)
@Override
public Result readSparse(RowBuffer buffer, RowCursor edit,
Out<Short> value) {
Result result = prepareSparseRead(buffer, edit, this.LayoutCode);
@Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Integer> value) {
Result result = prepareSparseRead(buffer, edit, this.layoutCode());
if (result != Result.SUCCESS) {
value.setAndGet(0);
value.set(0);
return result;
}
value.setAndGet(buffer.get().ReadSparseUInt16(edit));
value.set(buffer.readSparseUInt16(edit));
return Result.SUCCESS;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public override Result WriteFixed(ref RowBuffer b, ref RowCursor scope, LayoutColumn col, ushort
// value)
@Override
public Result WriteFixed(Reference<RowBuffer> b, Reference<RowCursor> scope, LayoutColumn col,
short value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT);
if (scope.get().immutable()) {
@Nonnull
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Integer value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
if (scope.immutable()) {
return Result.INSUFFICIENT_PERMISSIONS;
}
b.get().writeUInt16(scope.get().start() + col.getOffset(), value);
b.get().setBit(scope.get().start(), col.getNullBit().clone());
buffer.writeUInt16(scope.start() + column.offset(), value.shortValue());
buffer.setBit(scope.start(), column.nullBit());
return Result.SUCCESS;
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public override Result WriteSparse(ref RowBuffer b, ref RowCursor edit, ushort value,
// UpdateOptions options = UpdateOptions.Upsert)
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
@Override
public Result WriteSparse(Reference<RowBuffer> b, Reference<RowCursor> edit, short value,
UpdateOptions options) {
Result result = prepareSparseWrite(b, edit, this.typeArg().clone(), options);
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Integer value, UpdateOptions options) {
Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options);
if (result != Result.SUCCESS) {
return result;
}
b.get().writeSparseUInt16(edit, value, options);
buffer.writeSparseUInt16(edit, value.shortValue(), options);
return Result.SUCCESS;
}
@Override
public Result WriteSparse(Reference<RowBuffer> b, Reference<RowCursor> edit, short value) {
return WriteSparse(b, edit, value, UpdateOptions.Upsert);
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Integer value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
}

View File

@@ -4,93 +4,88 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out;
import com.azure.data.cosmos.core.Reference;
import com.azure.data.cosmos.serialization.hybridrow.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument;
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public sealed class LayoutUInt32 : LayoutType<uint>
public final class LayoutUInt32 extends LayoutType<Integer> {
public final class LayoutUInt32 extends LayoutType<Long> {
public LayoutUInt32() {
super(com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.UINT_32, (Integer.SIZE / Byte.SIZE));
super(LayoutCode.UINT_32, Integer.BYTES);
}
public boolean isFixed() {
return true;
}
@Nonnull
public String name() {
return "uint32";
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public override Result ReadFixed(ref RowBuffer b, ref RowCursor scope, LayoutColumn col, out
// uint value)
@Override
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column,
Out<Integer> value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT);
if (!buffer.get().readBit(scope.get().start(), column.getNullBit().clone())) {
value.setAndGet(0);
@Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Long> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
if (!buffer.readBit(scope.start(), column.nullBit())) {
value.set(0L);
return Result.NOT_FOUND;
}
value.setAndGet(buffer.get().ReadUInt32(scope.get().start() + column.getOffset()));
value.set(buffer.readUInt32(scope.start() + column.offset()));
return Result.SUCCESS;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public override Result ReadSparse(ref RowBuffer b, ref RowCursor edit, out uint value)
@Override
public Result readSparse(RowBuffer buffer, RowCursor edit,
Out<Integer> value) {
Result result = prepareSparseRead(buffer, edit, this.LayoutCode);
@Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Long> value) {
Result result = prepareSparseRead(buffer, edit, this.layoutCode());
if (result != Result.SUCCESS) {
value.setAndGet(0);
value.set(0L);
return result;
}
value.setAndGet(buffer.get().ReadSparseUInt32(edit));
value.set(buffer.readSparseUInt32(edit));
return Result.SUCCESS;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public override Result WriteFixed(ref RowBuffer b, ref RowCursor scope, LayoutColumn col, uint
// value)
@Override
public Result WriteFixed(Reference<RowBuffer> b, Reference<RowCursor> scope, LayoutColumn col,
int value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT);
if (scope.get().immutable()) {
@Nonnull
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Long value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
if (scope.immutable()) {
return Result.INSUFFICIENT_PERMISSIONS;
}
b.get().writeUInt32(scope.get().start() + col.getOffset(), value);
b.get().setBit(scope.get().start(), col.getNullBit().clone());
buffer.writeUInt32(scope.start() + column.offset(), value.intValue());
buffer.setBit(scope.start(), column.nullBit());
return Result.SUCCESS;
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public override Result WriteSparse(ref RowBuffer b, ref RowCursor edit, uint value,
// UpdateOptions options = UpdateOptions.Upsert)
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
@Override
public Result WriteSparse(Reference<RowBuffer> b, Reference<RowCursor> edit, int value,
UpdateOptions options) {
Result result = prepareSparseWrite(b, edit, this.typeArg().clone(), options);
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Long value, UpdateOptions options) {
Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options);
if (result != Result.SUCCESS) {
return result;
}
b.get().writeSparseUInt32(edit, value, options);
buffer.writeSparseUInt32(edit, value.intValue(), options);
return Result.SUCCESS;
}
@Override
public Result WriteSparse(Reference<RowBuffer> b, Reference<RowCursor> edit, int value) {
return WriteSparse(b, edit, value, UpdateOptions.Upsert);
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Long value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
}
}

View File

@@ -4,93 +4,92 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out;
import com.azure.data.cosmos.core.Reference;
import com.azure.data.cosmos.serialization.hybridrow.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument;
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public sealed class LayoutUInt64 : LayoutType<ulong>
public final class LayoutUInt64 extends LayoutType<Long> {
public LayoutUInt64() {
super(com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.UINT_64, (Long.SIZE / Byte.SIZE));
super(LayoutCode.UINT_64, Long.BYTES);
}
public boolean isFixed() {
return true;
}
@Nonnull
public String name() {
return "uint64";
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public override Result ReadFixed(ref RowBuffer b, ref RowCursor scope, LayoutColumn col, out
// ulong value)
@Override
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column,
Out<Long> value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT);
if (!buffer.get().readBit(scope.get().start(), column.getNullBit().clone())) {
value.setAndGet(0);
@Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Long> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
if (!buffer.readBit(scope.start(), column.nullBit())) {
value.set(0L);
return Result.NOT_FOUND;
}
value.setAndGet(buffer.get().ReadUInt64(scope.get().start() + column.getOffset()));
value.set(buffer.readUInt64(scope.start() + column.offset()));
return Result.SUCCESS;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public override Result ReadSparse(ref RowBuffer b, ref RowCursor edit, out ulong value)
@Override
public Result readSparse(RowBuffer buffer, RowCursor edit,
Out<Long> value) {
Result result = prepareSparseRead(buffer, edit, this.LayoutCode);
@Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Long> value) {
Result result = prepareSparseRead(buffer, edit, this.layoutCode());
if (result != Result.SUCCESS) {
value.setAndGet(0);
value.set(0L);
return result;
}
value.setAndGet(buffer.get().ReadSparseUInt64(edit));
value.set(buffer.readSparseUInt64(edit));
return Result.SUCCESS;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public override Result WriteFixed(ref RowBuffer b, ref RowCursor scope, LayoutColumn col, ulong
// value)
@Override
public Result WriteFixed(Reference<RowBuffer> b, Reference<RowCursor> scope, LayoutColumn col,
long value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT);
if (scope.get().immutable()) {
@Nonnull
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Long value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
if (scope.immutable()) {
return Result.INSUFFICIENT_PERMISSIONS;
}
b.get().writeUInt64(scope.get().start() + col.getOffset(), value);
b.get().setBit(scope.get().start(), col.getNullBit().clone());
buffer.writeUInt64(scope.start() + column.offset(), value);
buffer.setBit(scope.start(), column.nullBit());
return Result.SUCCESS;
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public override Result WriteSparse(ref RowBuffer b, ref RowCursor edit, ulong value,
// UpdateOptions options = UpdateOptions.Upsert)
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
@Override
public Result WriteSparse(Reference<RowBuffer> b, Reference<RowCursor> edit, long value,
UpdateOptions options) {
Result result = prepareSparseWrite(b, edit, this.typeArg().clone(), options);
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Long value, UpdateOptions options) {
Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options);
if (result != Result.SUCCESS) {
return result;
}
b.get().writeSparseUInt64(edit, value, options);
buffer.writeSparseUInt64(edit, value, options);
return Result.SUCCESS;
}
@Override
public Result WriteSparse(Reference<RowBuffer> b, Reference<RowCursor> edit, long value) {
return WriteSparse(b, edit, value, UpdateOptions.Upsert);
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Long value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
}

View File

@@ -4,93 +4,92 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out;
import com.azure.data.cosmos.core.Reference;
import com.azure.data.cosmos.serialization.hybridrow.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument;
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public sealed class LayoutUInt8 : LayoutType<byte>
public final class LayoutUInt8 extends LayoutType<Byte> {
public final class LayoutUInt8 extends LayoutType<Short> {
public LayoutUInt8() {
super(com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.UINT_8, 1);
super(LayoutCode.UINT_8, 1);
}
public boolean isFixed() {
return true;
}
@Nonnull
public String name() {
return "uint8";
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public override Result ReadFixed(ref RowBuffer b, ref RowCursor scope, LayoutColumn col, out
// byte value)
@Override
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column,
Out<Byte> value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT);
if (!buffer.get().readBit(scope.get().start(), column.getNullBit().clone())) {
value.setAndGet(0);
@Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Short> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
if (!buffer.readBit(scope.start(), column.nullBit())) {
value.set((short) 0);
return Result.NOT_FOUND;
}
value.setAndGet(buffer.get().ReadUInt8(scope.get().start() + column.getOffset()));
value.set(buffer.readUInt8(scope.start() + column.offset()));
return Result.SUCCESS;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public override Result ReadSparse(ref RowBuffer b, ref RowCursor edit, out byte value)
@Override
public Result readSparse(RowBuffer buffer, RowCursor edit,
Out<Byte> value) {
Result result = prepareSparseRead(buffer, edit, this.LayoutCode);
@Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Short> value) {
Result result = prepareSparseRead(buffer, edit, this.layoutCode());
if (result != Result.SUCCESS) {
value.setAndGet(0);
value.set((short) 0);
return result;
}
value.setAndGet(buffer.get().ReadSparseUInt8(edit));
value.set(buffer.readSparseUInt8(edit));
return Result.SUCCESS;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public override Result WriteFixed(ref RowBuffer b, ref RowCursor scope, LayoutColumn col, byte
// value)
@Override
public Result WriteFixed(Reference<RowBuffer> b, Reference<RowCursor> scope, LayoutColumn col,
byte value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT);
if (scope.get().immutable()) {
@Nonnull
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Short value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
if (scope.immutable()) {
return Result.INSUFFICIENT_PERMISSIONS;
}
b.get().writeUInt8(scope.get().start() + col.getOffset(), value);
b.get().setBit(scope.get().start(), col.getNullBit().clone());
buffer.writeUInt8(scope.start() + column.offset(), value.byteValue());
buffer.setBit(scope.start(), column.nullBit());
return Result.SUCCESS;
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public override Result WriteSparse(ref RowBuffer b, ref RowCursor edit, byte value,
// UpdateOptions options = UpdateOptions.Upsert)
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
@Override
public Result WriteSparse(Reference<RowBuffer> b, Reference<RowCursor> edit, byte value,
UpdateOptions options) {
Result result = prepareSparseWrite(b, edit, this.typeArg().clone(), options);
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Short value, UpdateOptions options) {
Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options);
if (result != Result.SUCCESS) {
return result;
}
b.get().writeSparseUInt8(edit, value, options);
buffer.writeSparseUInt8(edit, value.byteValue(), options);
return Result.SUCCESS;
}
@Override
public Result WriteSparse(Reference<RowBuffer> b, Reference<RowCursor> edit, byte value) {
return WriteSparse(b, edit, value, UpdateOptions.Upsert);
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Short value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
}

View File

@@ -21,6 +21,7 @@ public abstract class LayoutUniqueScope extends LayoutIndexedScope {
super(code, immutable, isSizedScope, false, true, isTypedScope);
}
@Nonnull
public abstract TypeArgument fieldType(RowCursor scope);
/**
@@ -35,10 +36,11 @@ public abstract class LayoutUniqueScope extends LayoutIndexedScope {
* @return Success a matching field exists in the unique index, NotFound if no match is found, the error code
* otherwise.
*/
@Nonnull
public final Result find(RowBuffer buffer, RowCursor scope, RowCursor patternScope, Out<RowCursor> value) {
Result result = LayoutType.prepareSparseMove(buffer, scope, this, this.fieldType(scope), patternScope,
UpdateOptions.Update, value);
UpdateOptions.UPDATE, value);
if (result != Result.SUCCESS) {
return result;
@@ -60,6 +62,7 @@ public abstract class LayoutUniqueScope extends LayoutIndexedScope {
* @param options The move options.
* @return Success if the field is permitted within the unique index, the error code otherwise.
*/
@Nonnull
public final Result moveField(
RowBuffer buffer, RowCursor destinationScope, RowCursor sourceEdit, UpdateOptions options) {
@@ -94,8 +97,9 @@ public abstract class LayoutUniqueScope extends LayoutIndexedScope {
* <para />
* The source field is delete whether the move succeeds or fails.
*/
@Nonnull
public final Result moveField(RowBuffer buffer, RowCursor destinationScope, RowCursor sourceEdit) {
return this.moveField(buffer, destinationScope, sourceEdit, UpdateOptions.Upsert);
return this.moveField(buffer, destinationScope, sourceEdit, UpdateOptions.UPSERT);
}
@Override
@@ -146,6 +150,6 @@ public abstract class LayoutUniqueScope extends LayoutIndexedScope {
@Nonnull
public <TContext> Result writeScope(
RowBuffer buffer, RowCursor scope, TypeArgumentList typeArgs, TContext context, WriterFunc<TContext> func) {
return this.writeScope(buffer, scope, typeArgs, context, func, UpdateOptions.Upsert);
return this.writeScope(buffer, scope, typeArgs, context, func, UpdateOptions.UPSERT);
}
}

View File

@@ -9,78 +9,86 @@ import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import com.azure.data.cosmos.serialization.hybridrow.UnixDateTime;
import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutUnixDateTime extends LayoutType<com.azure.data.cosmos.serialization.hybridrow.UnixDateTime> {
public final class LayoutUnixDateTime extends LayoutType<UnixDateTime> {
public LayoutUnixDateTime() {
super(com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.UNIX_DATE_TIME,
com.azure.data.cosmos.serialization.hybridrow.UnixDateTime.BYTES);
super(LayoutCode.UNIX_DATE_TIME, UnixDateTime.BYTES);
}
public boolean isFixed() {
return true;
}
@Nonnull
public String name() {
return "unixdatetime";
}
@Override
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column,
Out<UnixDateTime> value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT);
if (!buffer.get().readBit(scope.get().start(), column.getNullBit().clone())) {
value.setAndGet(null);
@Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<UnixDateTime> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
if (!buffer.readBit(scope.start(), column.nullBit())) {
value.set(null);
return Result.NOT_FOUND;
}
value.setAndGet(buffer.get().ReadUnixDateTime(scope.get().start() + column.getOffset()).clone());
value.set(buffer.readUnixDateTime(scope.start() + column.offset()));
return Result.SUCCESS;
}
@Override
public Result readSparse(RowBuffer buffer, RowCursor edit,
Out<UnixDateTime> value) {
Result result = prepareSparseRead(buffer, edit, this.LayoutCode);
@Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<UnixDateTime> value) {
Result result = prepareSparseRead(buffer, edit, this.layoutCode());
if (result != Result.SUCCESS) {
value.setAndGet(null);
value.set(null);
return result;
}
value.setAndGet(buffer.get().ReadSparseUnixDateTime(edit).clone());
value.set(buffer.readSparseUnixDateTime(edit));
return Result.SUCCESS;
}
@Override
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column,
UnixDateTime value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT);
if (scope.get().immutable()) {
@Nonnull
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, UnixDateTime value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
if (scope.immutable()) {
return Result.INSUFFICIENT_PERMISSIONS;
}
buffer.get().WriteUnixDateTime(scope.get().start() + column.getOffset(), value.clone());
buffer.get().SetBit(scope.get().start(), column.getNullBit().clone());
buffer.writeUnixDateTime(scope.start() + column.offset(), value);
buffer.setBit(scope.start(), column.nullBit());
return Result.SUCCESS;
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public override Result WriteSparse(ref RowBuffer b, ref RowCursor edit, UnixDateTime value,
// UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result writeSparse(RowBuffer buffer, RowCursor edit, UnixDateTime value
, UpdateOptions options) {
Result result = prepareSparseWrite(buffer, edit, this.typeArg().clone(), options);
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, UnixDateTime value, UpdateOptions options) {
Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options);
if (result != Result.SUCCESS) {
return result;
}
buffer.get().WriteSparseUnixDateTime(edit, value.clone(), options);
buffer.writeSparseUnixDateTime(edit, value, options);
return Result.SUCCESS;
}
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, UnixDateTime value) {
return writeSparse(buffer, edit, value, UpdateOptions.Upsert);
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
}

View File

@@ -4,184 +4,236 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out;
import com.azure.data.cosmos.core.Reference;
import com.azure.data.cosmos.core.Utf8String;
import com.azure.data.cosmos.serialization.hybridrow.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
public final class LayoutUtf8 extends LayoutType<String> implements ILayoutUtf8SpanWritable, ILayoutUtf8SpanReadable {
public LayoutUtf8() {
super(com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.UTF_8, 0);
super(LayoutCode.UTF_8, 0);
}
public boolean isFixed() {
return false;
}
@Nonnull
public String name() {
return "utf8";
}
@Override
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<String> value) {
Utf8Span span;
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
Result r = this.ReadFixed(buffer, scope, column, out span);
value.setAndGet((r == Result.SUCCESS) ? span.toString() :)
default
return r;
@Nonnull
public Result readFixed(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor scope,
@Nonnull final LayoutColumn column,
@Nonnull final Out<String> value) {
Out<Utf8String> span = new Out<>();
Result result = this.readFixedSpan(buffer, scope, column, span);
value.set(result == Result.SUCCESS ? span.get().toUtf16() : null);
return result;
}
public Result ReadFixed(Reference<RowBuffer> b, Reference<RowCursor> scope, LayoutColumn column,
Out<Utf8Span> value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT);
checkArgument(column.getSize() >= 0);
if (!b.get().readBit(scope.get().start(), column.getNullBit().clone())) {
value.setAndGet(null);
@Override
@Nonnull
public Result readFixedSpan(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor scope,
@Nonnull final LayoutColumn column,
@Nonnull final Out<Utf8String> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
checkArgument(column.size() >= 0);
if (!buffer.readBit(scope.start(), column.nullBit())) {
value.set(null);
return Result.NOT_FOUND;
}
value.setAndGet(b.get().readFixedString(scope.get().start() + column.getOffset(), column.getSize()));
value.set(buffer.readFixedString(scope.start() + column.offset(), column.size()));
return Result.SUCCESS;
}
@Override
public Result readSparse(RowBuffer buffer, RowCursor edit,
Out<String> value) {
Utf8Span span;
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
Result r = this.ReadSparse(buffer, edit, out span);
value.setAndGet((r == Result.SUCCESS) ? span.toString() :)
default
return r;
@Nonnull
public Result readSparse(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor edit,
@Nonnull final Out<String> value) {
Out<Utf8String> span = new Out<>();
Result result = this.readSparseSpan(buffer, edit, span);
value.set((result == Result.SUCCESS) ? span.get().toUtf16() : null);
return result;
}
public Result ReadSparse(Reference<RowBuffer> b, Reference<RowCursor> edit, Out<Utf8Span> value) {
Result result = LayoutType.prepareSparseRead(b, edit, this.LayoutCode);
@Override
@Nonnull
public Result readSparseSpan(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor edit,
@Nonnull final Out<Utf8String> value) {
Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode());
if (result != Result.SUCCESS) {
value.setAndGet(null);
value.set(null);
return result;
}
value.setAndGet(b.get().readSparseString(edit));
value.set(buffer.readSparseString(edit));
return Result.SUCCESS;
}
@Override
public Result readVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column
, Out<String> value) {
Utf8Span span;
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
Result r = this.ReadVariable(buffer, scope, column, out span);
value.setAndGet((r == Result.SUCCESS) ? span.toString() :)
default
return r;
@Nonnull
public Result readVariable(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor scope,
@Nonnull final LayoutColumn column,
@Nonnull final Out<String> value) {
Out<Utf8String> span = new Out<>();
Result result = this.readVariableSpan(buffer, scope, column, span);
value.set(result == Result.SUCCESS ? span.get().toUtf16() : null);
return result;
}
public Result ReadVariable(Reference<RowBuffer> b, Reference<RowCursor> scope, LayoutColumn col
, Out<Utf8Span> value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT);
if (!b.get().readBit(scope.get().start(), col.getNullBit().clone())) {
value.setAndGet(null);
@Override
@Nonnull
public Result readVariableSpan(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor scope,
@Nonnull final LayoutColumn column,
@Nonnull final Out<Utf8String> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
if (!buffer.readBit(scope.start(), column.nullBit())) {
value.set(null);
return Result.NOT_FOUND;
}
int varOffset = b.get().computeVariableValueOffset(scope.get().layout(), scope.get().start(),
col.getOffset());
value.setAndGet(b.get().readVariableString(varOffset));
int varOffset = buffer.computeVariableValueOffset(scope.layout(), scope.start(), column.offset());
value.set(buffer.readVariableString(varOffset));
return Result.SUCCESS;
}
@Override
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column,
String value) {
checkArgument(value != null);
return this.writeFixed(buffer, scope, column, Utf8Span.TranscodeUtf16(value));
@Nonnull
public Result writeFixed(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor scope,
@Nonnull final LayoutColumn column,
@Nonnull final String value) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(column, "expected non-null column");
checkNotNull(scope, "expected non-null scope");
checkNotNull(value, "expected non-null value");
return this.writeFixed(buffer, scope, column, Utf8String.transcodeUtf16(value));
}
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column,
Utf8String value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT);
checkArgument(column.getSize() >= 0);
checkArgument(value.Length == column.getSize());
if (scope.get().immutable()) {
@Override
@Nonnull
public Result writeFixed(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor scope,
@Nonnull final LayoutColumn column,
@Nonnull final Utf8String value) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(column, "expected non-null column");
checkNotNull(scope, "expected non-null scope");
checkNotNull(value, "expected non-null value");
checkArgument(scope.scopeType() instanceof LayoutUDT);
checkArgument(column.size() >= 0);
checkArgument(value.encodedLength() == column.size());
if (scope.immutable()) {
return Result.INSUFFICIENT_PERMISSIONS;
}
buffer.get().writeFixedString(scope.get().start() + column.getOffset(), value);
buffer.get().setBit(scope.get().start(), column.getNullBit().clone());
buffer.writeFixedString(scope.start() + column.offset(), value);
buffer.setBit(scope.start(), column.nullBit());
return Result.SUCCESS;
}
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, String value) {
return writeSparse(buffer, edit, value, UpdateOptions.Upsert);
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public override Result WriteSparse(ref RowBuffer b, ref RowCursor edit, string value,
// UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result writeSparse(RowBuffer buffer, RowCursor edit, String value,
UpdateOptions options) {
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, String value, UpdateOptions options) {
checkArgument(value != null);
return this.writeSparse(buffer, edit, Utf8Span.TranscodeUtf16(value), options);
return this.writeSparse(buffer, edit, Utf8String.transcodeUtf16(value), options);
}
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Utf8String value) {
return writeSparse(buffer, edit, value, UpdateOptions.Upsert);
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public Result WriteSparse(ref RowBuffer b, ref RowCursor edit, Utf8Span value, UpdateOptions
// options = UpdateOptions.Upsert)
public Result writeSparse(RowBuffer buffer, RowCursor edit, Utf8String value,
UpdateOptions options) {
Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg().clone(), options);
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Utf8String value, UpdateOptions options) {
Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options);
if (result != Result.SUCCESS) {
return result;
}
buffer.get().writeSparseString(edit, value, options);
buffer.writeSparseString(edit, value, options);
return Result.SUCCESS;
}
@Override
public Result writeVariable(RowBuffer buffer, RowCursor scope,
LayoutColumn column, String value) {
@Nonnull
public Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, String value) {
checkArgument(value != null);
return this.writeVariable(buffer, scope, column, Utf8Span.TranscodeUtf16(value));
return this.writeVariable(buffer, scope, column, Utf8String.transcodeUtf16(value));
}
public Result writeVariable(RowBuffer buffer, RowCursor scope,
LayoutColumn column, Utf8String value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT);
if (scope.get().immutable()) {
@Override
@Nonnull
public Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, Utf8String value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
if (scope.immutable()) {
return Result.INSUFFICIENT_PERMISSIONS;
}
int length = value.Length;
if ((column.getSize() > 0) && (length > column.getSize())) {
int length = value.encodedLength();
if ((column.size() > 0) && (length > column.size())) {
return Result.TOO_BIG;
}
boolean exists = buffer.get().readBit(scope.get().start(), column.getNullBit().clone());
int varOffset = buffer.get().computeVariableValueOffset(scope.get().layout(), scope.get().start(),
column.getOffset());
int shift;
Out<Integer> tempOut_shift = new Out<Integer>();
buffer.get().writeVariableString(varOffset, value, exists, tempOut_shift);
shift = tempOut_shift.get();
buffer.get().setBit(scope.get().start(), column.getNullBit().clone());
scope.get().metaOffset(scope.get().metaOffset() + shift);
scope.get().valueOffset(scope.get().valueOffset() + shift);
int offset = buffer.computeVariableValueOffset(scope.layout(), scope.start(), column.offset());
boolean exists = buffer.readBit(scope.start(), column.nullBit());
int shift = buffer.writeVariableString(offset, value, exists);
buffer.setBit(scope.start(), column.nullBit());
scope.metaOffset(scope.metaOffset() + shift);
scope.valueOffset(scope.valueOffset() + shift);
return Result.SUCCESS;
}
}

View File

@@ -4,16 +4,18 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out;
import com.azure.data.cosmos.core.Reference;
import com.azure.data.cosmos.serialization.hybridrow.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutVarInt extends LayoutType<Long> {
public LayoutVarInt() {
super(com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.VAR_INT, 0);
super(LayoutCode.VAR_INT, 0);
}
public boolean isFixed() {
@@ -24,89 +26,95 @@ public final class LayoutVarInt extends LayoutType<Long> {
return true;
}
@Nonnull
public String name() {
return "varint";
}
@Override
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column,
Out<Long> value) {
Contract.Fail("Not Implemented");
value.setAndGet(0);
@Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Long> value) {
assert false : "not implemented";
value.set(0L);
return Result.FAILURE;
}
@Override
@Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Long> value) {
Result result = LayoutType.prepareSparseRead(buffer, edit, this.LayoutCode);
Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode());
if (result != Result.SUCCESS) {
value.setAndGet(0);
value.set(0L);
return result;
}
value.setAndGet(buffer.get().ReadSparseVarInt(edit));
value.set(buffer.readSparseVarInt(edit));
return Result.SUCCESS;
}
@Override
public Result readVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Long> value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT);
if (!buffer.get().readBit(scope.get().start(), column.getNullBit().clone())) {
value.setAndGet(0);
@Nonnull
public Result readVariable(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<Long> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
if (!buffer.readBit(scope.start(), column.nullBit())) {
value.set(0L);
return Result.NOT_FOUND;
}
int varOffset = buffer.get().computeVariableValueOffset(scope.get().layout(), scope.get().start(),
column.getOffset());
value.setAndGet(buffer.get().ReadVariableInt(varOffset));
int varOffset = buffer.computeVariableValueOffset(scope.layout(), scope.start(), column.offset());
value.set(buffer.readVariableInt(varOffset));
return Result.SUCCESS;
}
@Override
public Result WriteFixed(Reference<RowBuffer> b, Reference<RowCursor> scope, LayoutColumn col,
long value) {
Contract.Fail("Not Implemented");
@Nonnull
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Long value) {
assert false : "not implemented";
return Result.FAILURE;
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public override Result WriteSparse(ref RowBuffer b, ref RowCursor edit, long value,
// UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result WriteSparse(Reference<RowBuffer> b, Reference<RowCursor> edit, long value,
UpdateOptions options) {
Result result = LayoutType.prepareSparseWrite(b, edit, this.typeArg().clone(), options);
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Long value, UpdateOptions options) {
Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options);
if (result != Result.SUCCESS) {
return result;
}
b.get().writeSparseVarInt(edit, value, options);
buffer.writeSparseVarInt(edit, value, options);
return Result.SUCCESS;
}
@Override
public Result WriteSparse(Reference<RowBuffer> b, Reference<RowCursor> edit, long value) {
return WriteSparse(b, edit, value, UpdateOptions.Upsert);
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Long value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
@Override
public Result WriteVariable(Reference<RowBuffer> b, Reference<RowCursor> scope,
LayoutColumn col, long value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT);
if (scope.get().immutable()) {
@Nonnull
public Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, Long value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
if (scope.immutable()) {
return Result.INSUFFICIENT_PERMISSIONS;
}
boolean exists = b.get().readBit(scope.get().start(), col.getNullBit().clone());
int varOffset = b.get().computeVariableValueOffset(scope.get().layout(), scope.get().start(),
col.getOffset());
int shift;
Out<Integer> tempOut_shift = new Out<Integer>();
b.get().writeVariableInt(varOffset, value, exists, tempOut_shift);
shift = tempOut_shift.get();
b.get().setBit(scope.get().start(), col.getNullBit().clone());
scope.get().metaOffset(scope.get().metaOffset() + shift);
scope.get().valueOffset(scope.get().valueOffset() + shift);
boolean exists = buffer.readBit(scope.start(), column.nullBit());
int varOffset = buffer.computeVariableValueOffset(scope.layout(), scope.start(), column.offset());
int shift = buffer.writeVariableInt(varOffset, value, exists);
buffer.setBit(scope.start(), column.nullBit());
scope.metaOffset(scope.metaOffset() + shift);
scope.valueOffset(scope.valueOffset() + shift);
return Result.SUCCESS;
}
}

View File

@@ -4,18 +4,18 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out;
import com.azure.data.cosmos.core.Reference;
import com.azure.data.cosmos.serialization.hybridrow.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument;
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public sealed class LayoutVarUInt : LayoutType<ulong>
public final class LayoutVarUInt extends LayoutType<Long> {
public LayoutVarUInt() {
super(com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.VAR_UINT, 0);
super(LayoutCode.VAR_UINT, 0);
}
public boolean isFixed() {
@@ -26,104 +26,95 @@ public final class LayoutVarUInt extends LayoutType<Long> {
return true;
}
@Nonnull
public String name() {
return "varuint";
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public override Result ReadFixed(ref RowBuffer b, ref RowCursor scope, LayoutColumn col, out
// ulong value)
@Override
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column,
Out<Long> value) {
Contract.Fail("Not Implemented");
value.setAndGet(0);
@Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Long> value) {
assert false : "not implemented";
value.set(0L);
return Result.FAILURE;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public override Result ReadSparse(ref RowBuffer b, ref RowCursor edit, out ulong value)
@Override
@Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Long> value) {
Result result = prepareSparseRead(buffer, edit, this.LayoutCode);
Result result = prepareSparseRead(buffer, edit, this.layoutCode());
if (result != Result.SUCCESS) {
value.setAndGet(0);
value.set(0L);
return result;
}
value.setAndGet(buffer.get().readSparseVarUInt(edit));
value.set(buffer.readSparseVarUInt(edit));
return Result.SUCCESS;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public override Result ReadVariable(ref RowBuffer b, ref RowCursor scope, LayoutColumn col, out
// ulong value)
@Override
public Result readVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Long> value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT);
if (!buffer.get().readBit(scope.get().start(), column.getNullBit().clone())) {
value.setAndGet(0);
@Nonnull
public Result readVariable(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<Long> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
if (!buffer.readBit(scope.start(), column.nullBit())) {
value.set(0L);
return Result.NOT_FOUND;
}
int varOffset = buffer.get().computeVariableValueOffset(scope.get().layout(), scope.get().start(),
column.getOffset());
value.setAndGet(buffer.get().ReadVariableUInt(varOffset));
int varOffset = buffer.computeVariableValueOffset(scope.layout(), scope.start(), column.offset());
value.set(buffer.readVariableUInt(varOffset));
return Result.SUCCESS;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public override Result WriteFixed(ref RowBuffer b, ref RowCursor scope, LayoutColumn col, ulong
// value)
@Override
public Result WriteFixed(Reference<RowBuffer> b, Reference<RowCursor> scope, LayoutColumn col,
long value) {
Contract.Fail("Not Implemented");
@Nonnull
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Long value) {
assert false : "not implemented";
return Result.FAILURE;
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public override Result WriteSparse(ref RowBuffer b, ref RowCursor edit, ulong value,
// UpdateOptions options = UpdateOptions.Upsert)
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
@Override
public Result WriteSparse(Reference<RowBuffer> b, Reference<RowCursor> edit, long value,
UpdateOptions options) {
Result result = prepareSparseWrite(b, edit, this.typeArg().clone(), options);
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Long value, UpdateOptions options) {
Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options);
if (result != Result.SUCCESS) {
return result;
}
b.get().writeSparseVarUInt(edit, value, options);
buffer.writeSparseVarUInt(edit, value, options);
return Result.SUCCESS;
}
@Override
public Result WriteSparse(Reference<RowBuffer> b, Reference<RowCursor> edit, long value) {
return WriteSparse(b, edit, value, UpdateOptions.Upsert);
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Long value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public override Result WriteVariable(ref RowBuffer b, ref RowCursor scope, LayoutColumn col,
// ulong value)
@Override
public Result WriteVariable(Reference<RowBuffer> b, Reference<RowCursor> scope,
LayoutColumn col, long value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT);
if (scope.get().immutable()) {
@Nonnull
public Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn col, Long value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
if (scope.immutable()) {
return Result.INSUFFICIENT_PERMISSIONS;
}
boolean exists = b.get().readBit(scope.get().start(), col.getNullBit().clone());
int varOffset = b.get().computeVariableValueOffset(scope.get().layout(), scope.get().start(),
col.getOffset());
int shift;
Out<Integer> tempOut_shift = new Out<Integer>();
b.get().writeVariableUInt(varOffset, value, exists, tempOut_shift);
shift = tempOut_shift.get();
b.get().setBit(scope.get().start(), col.getNullBit().clone());
scope.get().metaOffset(scope.get().metaOffset() + shift);
scope.get().valueOffset(scope.get().valueOffset() + shift);
final boolean exists = buffer.readBit(scope.start(), col.nullBit());
final int varOffset = buffer.computeVariableValueOffset(scope.layout(), scope.start(), col.offset());
final int shift = buffer.writeVariableUInt(varOffset, value, exists);
buffer.setBit(scope.start(), col.nullBit());
scope.metaOffset(scope.metaOffset() + shift);
scope.valueOffset(scope.valueOffset() + shift);
return Result.SUCCESS;
}
}

View File

@@ -4,49 +4,68 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.serialization.hybridrow.SchemaId;
import com.azure.data.cosmos.serialization.hybridrow.schemas.Namespace;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Optional;
import static com.google.common.base.Preconditions.checkState;
public final class SystemSchema {
/**
* SchemaId of the empty schema. This schema has no defined cells but can accomodate
* unschematized sparse content.
*/
public static final SchemaId EmptySchemaId = new SchemaId(2147473650);
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutResolver LayoutResolver = SystemSchema
// .LoadSchema();
public static final LayoutResolver LayoutResolver = SystemSchema.LoadSchema();
public static final SchemaId EMPTY_SCHEMA_ID = SchemaId.from(2147473650);
/**
* SchemaId of HybridRow RecordIO Record Headers.
*/
public static final SchemaId RecordSchemaId = new SchemaId(2147473649);
public static final SchemaId RECORD_SCHEMA_ID = SchemaId.from(2147473649);
/**
* SchemaId of HybridRow RecordIO Segments.
*/
public static final SchemaId SegmentSchemaId = new SchemaId(2147473648);
public static final SchemaId SEGMENT_SCHEMA_ID = SchemaId.from(2147473648);
public static final LayoutResolver layoutResolver = SystemSchema.loadSchema();
private SystemSchema() {
}
/*
private static String FormatResourceName(Assembly assembly, String resourceName) {
return assembly.GetName().Name + "." + resourceName.replace(" ", "_").replace("\\", ".").replace("/", ".");
}
*/
private static String GetEmbeddedResource(String resourceName) {
Assembly assembly = Assembly.GetAssembly(RecordIOFormatter.class);
resourceName = SystemSchema.FormatResourceName(assembly, resourceName);
try (Stream resourceStream = assembly.GetManifestResourceStream(resourceName)) {
if (resourceStream == null) {
return null;
}
static LayoutResolver loadSchema() {
try (InputStreamReader reader = new InputStreamReader(resourceStream)) {
return reader.ReadToEnd();
final String json;
try {
json = SystemSchema.readFromResourceFile("system-schema.json");
} catch (IOException cause) {
throw new IllegalStateException("failed to load system-schema.json", cause);
}
Optional<Namespace> ns = Namespace.parse(json);
checkState(ns.isPresent(), "failed to load system-schema.json");
return new LayoutResolverNamespace(ns.get());
}
@SuppressWarnings("StatementWithEmptyBody")
private static String readFromResourceFile(String name) throws IOException {
try (final InputStream stream = SystemSchema.class.getResourceAsStream(name)) {
ByteBuf buffer = Unpooled.buffer();
while (buffer.writeBytes(stream, 8192) == 8192) {
}
return buffer.readCharSequence(buffer.readableBytes(), StandardCharsets.UTF_8).toString();
}
}
private static LayoutResolver LoadSchema() {
String json = SystemSchema.GetEmbeddedResource("SystemSchemas\\SystemSchema.json");
Namespace ns = Namespace.Parse(json);
LayoutResolverNamespace resolver = new LayoutResolverNamespace(ns);
return resolver;
}
}
}

View File

@@ -3,14 +3,15 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts;
import java.util.HashMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
/**
* Describes the desired behavior when writing a {@link LayoutType}.
*/
public enum UpdateOptions {
None(0),
NONE(0),
/**
* Overwrite an existing value.
@@ -19,35 +20,34 @@ public enum UpdateOptions {
* replaced inline. The remainder of the row is resized to accomodate either an increase or decrease
* in required space.
*/
Update(1),
UPDATE(1),
/**
* Insert a new value.
* Insert a new value
* <p>
* An existing value is assumed NOT to exist at the offset provided. The new value is
* inserted immediately at the offset. The remainder of the row is resized to accomodate either an
* increase or decrease in required space.
* An existing value is assumed NOT to exist at the offset provided. The new value is inserted immediately at the
* offset. The remainder of the row is resized to accommodate either an increase or decrease in required space.
*/
Insert(2),
INSERT(2),
/**
* Update an existing value or insert a new value, if no value exists.
* Update an existing value or insert a new value, if no value exists
* <p>
* If a value exists, then this operation becomes {@link Update}, otherwise it becomes
* {@link Insert}.
* If a value exists, then this operation becomes {@link #UPDATE}, otherwise it becomes {@link #INSERT}.
*/
Upsert(3),
UPSERT(3),
/**
* Insert a new value moving existing values to the right.
* <p>
* Within an array scope, inserts a new value immediately at the index moving all subsequent
* items to the right. In any other scope behaves the same as {@link Upsert}.
* items to the right. In any other scope behaves the same as {@link #UPSERT}.
*/
InsertAt(4);
INSERT_AT(4);
public static final int SIZE = java.lang.Integer.SIZE;
private static java.util.HashMap<Integer, UpdateOptions> mappings;
public static final int BYTES = Integer.BYTES;
private static Int2ObjectMap<UpdateOptions> mappings;
private int value;
UpdateOptions(int value) {
@@ -55,19 +55,19 @@ public enum UpdateOptions {
mappings().put(value, this);
}
public int value() {
return this.value;
}
public static UpdateOptions from(int value) {
return mappings().get(value);
}
private static java.util.HashMap<Integer, UpdateOptions> mappings() {
public int value() {
return this.value;
}
private static Int2ObjectMap<UpdateOptions> mappings() {
if (mappings == null) {
synchronized (UpdateOptions.class) {
if (mappings == null) {
mappings = new HashMap<>();
mappings = new Int2ObjectOpenHashMap<>();
}
}
}

View File

@@ -3,35 +3,35 @@
package com.azure.data.cosmos.serialization.hybridrow.recordio;
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
///#pragma warning disable CA1051 // Do not declare visible instance fields
//C# TO JAVA CONVERTER WARNING: Java does not allow user-defined value types. The behavior of this class may differ
// from the original:
//ORIGINAL LINE: public struct Record
public final class Record {
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public uint Crc32;
public int Crc32;
public int Length;
public Record() {
public static Record empty() {
return new Record(0, 0);
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public Record(int length, uint crc32)
private int crc32;
private int length;
public Record(int length, int crc32) {
this.Length = length;
this.Crc32 = crc32;
this.length = length;
this.crc32 = crc32;
}
public Record clone() {
Record varCopy = new Record();
public int crc32() {
return this.crc32;
}
varCopy.Length = this.Length;
varCopy.Crc32 = this.Crc32;
public Record crc32(int value) {
this.crc32 = value;
return this;
}
return varCopy;
public int length() {
return this.length;
}
public Record length(int value) {
this.length = value;
return this;
}
}

View File

@@ -13,8 +13,9 @@ import com.azure.data.cosmos.serialization.hybridrow.layouts.Layout;
import com.azure.data.cosmos.serialization.hybridrow.layouts.SystemSchema;
public final class RecordIOFormatter {
public static final Layout RecordLayout = SystemSchema.LayoutResolver.resolve(SystemSchema.RecordSchemaId);
public static final Layout SegmentLayout = SystemSchema.LayoutResolver.resolve(SystemSchema.SegmentSchemaId);
public static final Layout RECORD_LAYOUT = SystemSchema.layoutResolver.resolve(SystemSchema.RECORD_SCHEMA_ID);
public static final Layout SEGMENT_LAYOUT = SystemSchema.layoutResolver.resolve(SystemSchema.SEGMENT_SCHEMA_ID);
public static Result FormatRecord(ReadOnlyMemory<Byte> body, Out<RowBuffer> row) {
return FormatRecord(body, row, null);
@@ -29,12 +30,12 @@ public final class RecordIOFormatter {
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: resizer = resizer != null ? resizer : DefaultSpanResizer<byte>.Default;
resizer = resizer != null ? resizer : DefaultSpanResizer < Byte >.Default;
int estimatedSize = HybridRowHeader.BYTES + RecordIOFormatter.RecordLayout.getSize() + body.Length;
int estimatedSize = HybridRowHeader.BYTES + RecordIOFormatter.RECORD_LAYOUT.getSize() + body.Length;
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: uint crc32 = Crc32.Update(0, body.Span);
int crc32 = Crc32.Update(0, body.Span);
Record record = new Record(body.Length, crc32);
return RecordIOFormatter.FormatObject(resizer, estimatedSize, RecordIOFormatter.RecordLayout, record.clone(),
return RecordIOFormatter.FormatObject(resizer, estimatedSize, RecordIOFormatter.RECORD_LAYOUT, record.clone(),
RecordSerializer.Write, row.clone());
}
@@ -51,11 +52,11 @@ public final class RecordIOFormatter {
//ORIGINAL LINE: resizer = resizer != null ? resizer : DefaultSpanResizer<byte>.Default;
resizer = resizer != null ? resizer : DefaultSpanResizer < Byte >.Default;
int estimatedSize =
HybridRowHeader.BYTES + RecordIOFormatter.SegmentLayout.getSize() + segment.Comment == null ? null :
segment.Comment.length() != null ? segment.Comment.length() : 0 + segment.SDL == null ? null :
segment.SDL.length() != null ? segment.SDL.length() : 0 + 20;
HybridRowHeader.BYTES + RecordIOFormatter.SEGMENT_LAYOUT.getSize() + segment.comment() == null ? null :
segment.comment().length() != null ? segment.comment().length() : 0 + segment.sdl() == null ? null :
segment.sdl().length() != null ? segment.sdl().length() : 0 + 20;
return RecordIOFormatter.FormatObject(resizer, estimatedSize, RecordIOFormatter.SegmentLayout,
return RecordIOFormatter.FormatObject(resizer, estimatedSize, RecordIOFormatter.SEGMENT_LAYOUT,
segment.clone(), SegmentSerializer.Write, row.clone());
}
@@ -65,7 +66,7 @@ public final class RecordIOFormatter {
private static <T> Result FormatObject(ISpanResizer<Byte> resizer, int initialCapacity, Layout layout, T obj,
RowWriter.WriterFunc<T> writer, Out<RowBuffer> row) {
row.setAndGet(new RowBuffer(initialCapacity, resizer));
row.get().initLayout(HybridRowVersion.V1, layout, SystemSchema.LayoutResolver);
row.get().initLayout(HybridRowVersion.V1, layout, SystemSchema.layoutResolver);
Result r = RowWriter.WriteBuffer(row.clone(), obj, writer);
if (r != Result.SUCCESS) {
row.setAndGet(null);

View File

@@ -12,75 +12,73 @@ import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.SchemaId;
import com.azure.data.cosmos.serialization.hybridrow.io.RowReader;
import com.azure.data.cosmos.serialization.hybridrow.layouts.SystemSchema;
import io.netty.buffer.ByteBuf;
import it.unimi.dsi.fastutil.bytes.Byte2ObjectMap;
import it.unimi.dsi.fastutil.bytes.Byte2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkState;
//C# TO JAVA CONVERTER WARNING: Java does not allow user-defined value types. The behavior of this class may differ
// from the original:
//ORIGINAL LINE: public struct RecordIOParser
public final class RecordIOParser {
private Record record = new Record();
private Segment segment = new Segment();
private Record record;
private Segment segment;
private State state = State.values()[0];
/**
* True if a valid segment has been parsed.
*/
public boolean getHaveSegment() {
return this.state.getValue() >= State.NeedHeader.getValue();
}
/**
* If a valid segment has been parsed then current active segment, otherwise undefined.
*/
public Segment getSegment() {
checkArgument(this.getHaveSegment());
return this.segment.clone();
}
/**
* Processes one buffers worth of data possibly advancing the parser state.
* Processes one buffers worth of data possibly advancing the parser state
*
* @param buffer The buffer to consume.
* @param type Indicates the type of Hybrid Row produced in <paramref name="record" />.
* @param record If non-empty, then the body of the next record in the sequence.
* @param need The smallest number of bytes needed to advanced the parser state further. It is
* recommended that Process not be called again until at least this number of bytes are available.
* @param consumed The number of bytes consumed from the input buffer. This number may be less
* than the total buffer size if the parser moved to a new state.
* @return {@link azure.data.cosmos.serialization.hybridrow.Result.Success} if no error
* has occurred, otherwise a valid
* {@link azure.data.cosmos.serialization.hybridrow.Result} of the last error encountered
* during parsing.
* @param buffer1 The buffer to consume
* @param type Indicates the type of Hybrid Row produced in {@code record}
* @param record If non-empty, then the body of the next record in the sequence
* @param need The smallest number of bytes needed to advanced the parser state further
* <p>
* It is recommended that this method not be called again until at least this number of bytes are
* available.
* @param consumed The number of bytes consumed from the input buffer
* <p>
* This number may be less than the total buffer size if the parser moved to a new state.
* @return {@link Result#SUCCESS} if no error has occurred;, otherwise the {@link Result} of the last error
* encountered during parsing.
* <p>
* >
*/
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public Result Process(Memory<byte> buffer, out ProductionType type, out Memory<byte> record, out
// int need, out int consumed)
public Result Process(Memory<Byte> buffer, Out<ProductionType> type,
Out<Memory<Byte>> record, Out<Integer> need,
Out<Integer> consumed) {
Result r = Result.FAILURE;
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: Memory<byte> b = buffer;
Memory<Byte> b = buffer;
type.setAndGet(ProductionType.None);
record.setAndGet(null);
@Nonnull
public Result process(
@Nonnull final ByteBuf buffer,
@Nonnull final Out<ProductionType> type,
@Nonnull final Out<ByteBuf> record,
@Nonnull final Out<Integer> need,
@Nonnull final Out<Integer> consumed) {
Result result = Result.FAILURE;
type.set(ProductionType.NONE);
record.set(null);
final int start = buffer.readerIndex();
switch (this.state) {
case Start:
this.state = State.NeedSegmentLength;
case STATE:
this.state = State.NEED_SEGMENT_LENGTH;
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
case NeedSegmentLength: {
int minimalSegmentRowSize = HybridRowHeader.BYTES + RecordIOFormatter.SegmentLayout.getSize();
if (b.Length < minimalSegmentRowSize) {
need.setAndGet(minimalSegmentRowSize);
consumed.setAndGet(buffer.Length - b.Length);
// goto case State.NeedSegmentLength;
case NEED_SEGMENT_LENGTH: {
final int minimalSegmentRowSize = HybridRowHeader.BYTES + RecordIOFormatter.SEGMENT_LAYOUT.size();
if (buffer.readableBytes() < minimalSegmentRowSize) {
consumed.set(buffer.readerIndex() - start);
need.set(minimalSegmentRowSize);
return Result.INSUFFICIENT_BUFFER;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: Span<byte> span = b.Span.Slice(0, minimalSegmentRowSize);
Span<Byte> span = b.Span.Slice(0, minimalSegmentRowSize);
RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.LayoutResolver);
ByteBuf span = buffer.slice(buffer.readerIndex(), minimalSegmentRowSize);
RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.layoutResolver);
Reference<RowBuffer> tempReference_row =
new Reference<RowBuffer>(row);
RowReader reader = new RowReader(tempReference_row);
@@ -89,29 +87,29 @@ public final class RecordIOParser {
new Reference<RowReader>(reader);
Out<Segment> tempOut_segment =
new Out<Segment>();
r = SegmentSerializer.Read(tempReference_reader, tempOut_segment);
result = SegmentSerializer.Read(tempReference_reader, tempOut_segment);
this.segment = tempOut_segment.get();
reader = tempReference_reader.get();
if (r != Result.SUCCESS) {
if (result != Result.SUCCESS) {
break;
}
this.state = State.NeedSegment;
this.state = State.NEED_SEGMENT;
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
goto case State.NeedSegment
goto case State.NEED_SEGMENT
}
case NeedSegment: {
if (b.Length < this.segment.Length) {
need.setAndGet(this.segment.Length);
consumed.setAndGet(buffer.Length - b.Length);
case NEED_SEGMENT: {
if (buffer.Length < this.segment.length()) {
need.set(this.segment.length());
consumed.set(buffer.Length - buffer.Length);
return Result.INSUFFICIENT_BUFFER;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: Span<byte> span = b.Span.Slice(0, this.segment.Length);
Span<Byte> span = b.Span.Slice(0, this.segment.Length);
RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.LayoutResolver);
Span<Byte> span = buffer.Span.Slice(0, this.segment.length());
RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.layoutResolver);
Reference<RowBuffer> tempReference_row2 =
new Reference<RowBuffer>(row);
RowReader reader = new RowReader(tempReference_row2);
@@ -120,26 +118,26 @@ public final class RecordIOParser {
new Reference<RowReader>(reader);
Out<Segment> tempOut_segment2
= new Out<Segment>();
r = SegmentSerializer.Read(tempReference_reader2, tempOut_segment2);
result = SegmentSerializer.Read(tempReference_reader2, tempOut_segment2);
this.segment = tempOut_segment2.get();
reader = tempReference_reader2.get();
if (r != Result.SUCCESS) {
if (result != Result.SUCCESS) {
break;
}
record.setAndGet(b.Slice(0, span.Length));
b = b.Slice(span.Length);
need.setAndGet(0);
this.state = State.NeedHeader;
consumed.setAndGet(buffer.Length - b.Length);
type.setAndGet(ProductionType.Segment);
record.set(buffer.Slice(0, span.Length));
buffer = buffer.Slice(span.Length);
need.set(0);
this.state = State.NEED_HEADER;
consumed.set(buffer.Length - buffer.Length);
type.set(ProductionType.SEGMENT);
return Result.SUCCESS;
}
case NeedHeader: {
if (b.Length < HybridRowHeader.BYTES) {
need.setAndGet(HybridRowHeader.BYTES);
consumed.setAndGet(buffer.Length - b.Length);
case NEED_HEADER: {
if (buffer.Length < HybridRowHeader.BYTES) {
need.set(HybridRowHeader.BYTES);
consumed.set(buffer.Length - buffer.Length);
return Result.INSUFFICIENT_BUFFER;
}
@@ -147,100 +145,105 @@ public final class RecordIOParser {
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword -
// these cannot be converted using the 'Out' helper class unless the method is within the code
// being modified:
MemoryMarshal.TryRead(b.Span, out header);
MemoryMarshal.TryRead(buffer.Span, out header);
if (header.Version != HybridRowVersion.V1) {
r = Result.INVALID_ROW;
result = Result.INVALID_ROW;
break;
}
if (SchemaId.opEquals(header.SchemaId,
SystemSchema.SegmentSchemaId)) {
SystemSchema.SEGMENT_SCHEMA_ID)) {
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
goto case State.NeedSegment
goto case State.NEED_SEGMENT
}
if (SchemaId.opEquals(header.SchemaId,
SystemSchema.RecordSchemaId)) {
SystemSchema.RECORD_SCHEMA_ID)) {
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
goto case State.NeedRecord
goto case State.NEED_RECORD
}
r = Result.INVALID_ROW;
result = Result.INVALID_ROW;
break;
}
case NeedRecord: {
int minimalRecordRowSize = HybridRowHeader.BYTES + RecordIOFormatter.RecordLayout.getSize();
if (b.Length < minimalRecordRowSize) {
need.setAndGet(minimalRecordRowSize);
consumed.setAndGet(buffer.Length - b.Length);
case NEED_RECORD: {
int minimalRecordRowSize = HybridRowHeader.BYTES + RecordIOFormatter.RECORD_LAYOUT.size();
if (buffer.Length < minimalRecordRowSize) {
need.set(minimalRecordRowSize);
consumed.set(buffer.Length - buffer.Length);
return Result.INSUFFICIENT_BUFFER;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: Span<byte> span = b.Span.Slice(0, minimalRecordRowSize);
Span<Byte> span = b.Span.Slice(0, minimalRecordRowSize);
RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.LayoutResolver);
Span<Byte> span = buffer.Span.Slice(0, minimalRecordRowSize);
RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.layoutResolver);
Reference<RowBuffer> tempReference_row3 =
new Reference<RowBuffer>(row);
RowReader reader = new RowReader(tempReference_row3);
row = tempReference_row3.get();
Reference<RowReader> tempReference_reader3 = new Reference<RowReader>(reader);
Out<Record> tempOut_record = new Out<Record>();
r = RecordSerializer.Read(tempReference_reader3, tempOut_record);
result = RecordSerializer.read(tempReference_reader3, tempOut_record);
this.record = tempOut_record.get();
reader = tempReference_reader3.get();
if (r != Result.SUCCESS) {
if (result != Result.SUCCESS) {
break;
}
b = b.Slice(span.Length);
this.state = State.NeedRow;
buffer = buffer.Slice(span.Length);
this.state = State.NEED_ROW;
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
goto case State.NeedRow
goto case State.NEED_ROW
}
case NeedRow: {
if (b.Length < this.record.Length) {
need.setAndGet(this.record.Length);
consumed.setAndGet(buffer.Length - b.Length);
case NEED_ROW: {
if (buffer.Length < this.record.length()) {
need.set(this.record.length());
consumed.set(buffer.Length - buffer.Length);
return Result.INSUFFICIENT_BUFFER;
}
record.setAndGet(b.Slice(0, this.record.Length));
record.set(buffer.Slice(0, this.record.length()));
// Validate that the record has not been corrupted.
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: uint crc32 = Crc32.Update(0, record.Span);
int crc32 = Crc32.Update(0, record.get().Span);
if (crc32 != this.record.Crc32) {
r = Result.INVALID_ROW;
if (crc32 != this.record.crc32()) {
result = Result.INVALID_ROW;
break;
}
b = b.Slice(this.record.Length);
need.setAndGet(0);
this.state = State.NeedHeader;
consumed.setAndGet(buffer.Length - b.Length);
type.setAndGet(ProductionType.Record);
buffer = buffer.Slice(this.record.length());
need.set(0);
this.state = State.NEED_HEADER;
consumed.set(buffer.Length - buffer.Length);
type.set(ProductionType.RECORD);
return Result.SUCCESS;
}
}
this.state = State.Error;
need.setAndGet(0);
consumed.setAndGet(buffer.Length - b.Length);
return r;
this.state = State.ERROR;
need.set(0);
consumed.set(buffer.Length - buffer.Length);
return result;
}
public RecordIOParser clone() {
RecordIOParser varCopy = new RecordIOParser();
/**
* True if a valid segment has been parsed.
*/
public boolean haveSegment() {
return this.state.value() >= State.NEED_HEADER.value();
}
varCopy.state = this.state;
varCopy.segment = this.segment.clone();
varCopy.record = this.record.clone();
return varCopy;
/**
* If a valid segment has been parsed then current active segment, otherwise undefined.
*/
public Segment segment() {
checkState(this.haveSegment());
return this.segment;
}
/**
@@ -250,40 +253,41 @@ public final class RecordIOParser {
/**
* No hybrid row was produced. The parser needs more data.
*/
None(0),
NONE(0),
/**
* A new segment row was produced.
*/
Segment(1),
SEGMENT(1),
/**
* A record in the current segment was produced.
*/
Record(2);
RECORD(2);
public static final int SIZE = java.lang.Integer.SIZE;
private static java.util.HashMap<Integer, ProductionType> mappings;
private int intValue;
public static final int BYTES = Integer.BYTES;
private static Int2ObjectMap<ProductionType> mappings;
private int value;
ProductionType(int value) {
intValue = value;
getMappings().put(value, this);
this.value = value;
mappings().put(value, this);
}
public int getValue() {
return intValue;
public int value() {
return this.value;
}
public static ProductionType forValue(int value) {
return getMappings().get(value);
public static ProductionType from(int value) {
return mappings().get(value);
}
private static java.util.HashMap<Integer, ProductionType> getMappings() {
private static Int2ObjectMap<ProductionType> mappings() {
if (mappings == null) {
synchronized (ProductionType.class) {
if (mappings == null) {
mappings = new java.util.HashMap<Integer, ProductionType>();
mappings = new Int2ObjectOpenHashMap<>();
}
}
}
@@ -295,39 +299,51 @@ public final class RecordIOParser {
* The states for the internal state machine.
* Note: numerical ordering of these states matters.
*/
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: private enum State : byte
private enum State {
Start((byte)0), // Start: no buffers have yet been provided to the parser.
Error(((byte)0) + 1), // Unrecoverable parse error encountered.
NeedSegmentLength(((byte)0) + 2), // Parsing segment header length
NeedSegment(((byte)0) + 3), // Parsing segment header
NeedHeader(((byte)0) + 4), // Parsing HybridRow header
NeedRecord(((byte)0) + 5), // Parsing record header
NeedRow(((byte)0) + 6); // Parsing row body
STATE(
(byte) 0, "Start: no buffers have yet been provided to the parser"),
ERROR(
(byte) 1, "Unrecoverable parse error encountered"),
NEED_SEGMENT_LENGTH(
(byte) 2, "Parsing segment header length"),
NEED_SEGMENT(
(byte) 3, "Parsing segment header"),
NEED_HEADER(
(byte) 4, "Parsing HybridRow header"),
NEED_RECORD(
(byte) 5, "Parsing record header"),
NEED_ROW(
(byte) 6, "Parsing row body");
public static final int SIZE = java.lang.Byte.SIZE;
private static java.util.HashMap<Byte, State> mappings;
private byte byteValue;
public static final int BYTES = Byte.SIZE;
State(byte value) {
byteValue = value;
getMappings().put(value, this);
private static Byte2ObjectMap<State> mappings;
private final String description;
private final byte value;
State(byte value, String description) {
this.description = description;
this.value = value;
mappings().put(value, this);
}
public byte getValue() {
return byteValue;
public String description() {
return this.description;
}
public static State forValue(byte value) {
return getMappings().get(value);
public byte value() {
return this.value;
}
private static java.util.HashMap<Byte, State> getMappings() {
public static State from(byte value) {
return mappings().get(value);
}
private static Byte2ObjectMap<State> mappings() {
if (mappings == null) {
synchronized (State.class) {
if (mappings == null) {
mappings = new java.util.HashMap<Byte, State>();
mappings = new Byte2ObjectOpenHashMap<>();
}
}
}

View File

@@ -117,7 +117,7 @@ public final class RecordIOStream {
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: Result r = parser.Process(avail, out RecordIOParser.ProductionType prodType, out
// Memory<byte> record, out need, out int consumed);
Result r = parser.Process(avail, tempOut_prodType, tempOut_record, tempOut_need, tempOut_consumed);
Result r = parser.process(avail, tempOut_prodType, tempOut_record, tempOut_need, tempOut_consumed);
consumed = tempOut_consumed.get();
need = tempOut_need.get();
record = tempOut_record.get();
@@ -145,7 +145,7 @@ public final class RecordIOStream {
}
// Validate the Segment
if (prodType == RecordIOParser.ProductionType.Segment) {
if (prodType == RecordIOParser.ProductionType.SEGMENT) {
checkState(!record.IsEmpty);
r = visitSegment == null ? null : visitSegment.invoke(record) != null ?
visitSegment.invoke(record) : Result.SUCCESS;
@@ -155,7 +155,7 @@ public final class RecordIOStream {
}
// Consume the record.
if (prodType == RecordIOParser.ProductionType.Record) {
if (prodType == RecordIOParser.ProductionType.RECORD) {
checkState(!record.IsEmpty);
r = visitRecord.invoke(record);

View File

@@ -4,36 +4,52 @@
package com.azure.data.cosmos.serialization.hybridrow.recordio;
import com.azure.data.cosmos.core.Out;
import com.azure.data.cosmos.core.Reference;
import com.azure.data.cosmos.core.UtfAnyString;
import com.azure.data.cosmos.serialization.hybridrow.Result;
import com.azure.data.cosmos.serialization.hybridrow.io.RowReader;
import com.azure.data.cosmos.serialization.hybridrow.io.RowWriter;
import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument;
import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkState;
public final class RecordSerializer {
public static Result Read(Reference<RowReader> reader, Out<Record> obj) {
obj.setAndGet(null);
while (reader.get().Read()) {
Result r;
// TODO: use Path tokens here.
switch (reader.get().getPath().toString()) {
@Nonnull
public static Result read(RowReader reader, Out<Record> record) {
Out<Integer> value = new Out<>();
record.set(Record.empty());
while (reader.read()) {
String path = reader.path().toUtf16();
checkState(path != null);
Result result;
// TODO: use Path tokens here
switch (path) {
case "length":
Out<Integer> tempOut_Length = new Out<Integer>();
r = reader.get().ReadInt32(tempOut_Length);
obj.get().argValue.Length = tempOut_Length.get();
if (r != Result.SUCCESS) {
return r;
}
result = reader.readInt32(value);
record.get().length(value.get());
if (result != Result.SUCCESS) {
return result;
}
break;
case "crc32":
Out<Integer> tempOut_Crc32 = new Out<Integer>();
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: r = reader.ReadUInt32(out obj.Crc32);
r = reader.get().ReadUInt32(tempOut_Crc32);
obj.get().argValue.Crc32 = tempOut_Crc32.get();
if (r != Result.SUCCESS) {
return r;
}
case "crc32":
result = reader.readInt32(value);
record.get().crc32(value.get());
if (result != Result.SUCCESS) {
return result;
}
break;
}
}
@@ -41,14 +57,12 @@ public final class RecordSerializer {
return Result.SUCCESS;
}
public static Result Write(Reference<RowWriter> writer, TypeArgument typeArg, Record obj) {
Result r;
r = writer.get().WriteInt32("length", obj.Length);
if (r != Result.SUCCESS) {
return r;
@Nonnull
public static Result write(RowWriter writer, TypeArgument typeArg, Record record) {
Result result = writer.writeInt32(new UtfAnyString("length"), record.length());
if (result != Result.SUCCESS) {
return result;
}
r = writer.get().WriteUInt32("crc32", obj.Crc32);
return r;
return writer.writeUInt32(new UtfAnyString("crc32"), record.crc32());
}
}

View File

@@ -3,34 +3,27 @@
package com.azure.data.cosmos.serialization.hybridrow.recordio;
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
///#pragma warning disable CA1051 // Do not declare visible instance fields
//C# TO JAVA CONVERTER WARNING: Java does not allow user-defined value types. The behavior of this class may differ
// from the original:
//ORIGINAL LINE: public struct Segment
public final class Segment {
public String Comment;
public int Length;
public String SDL;
public Segment() {
}
private final String comment;
private final int length;
private final String sdl;
public Segment(String comment, String sdl) {
this.Length = 0;
this.Comment = comment;
this.SDL = sdl;
this.comment = comment;
this.sdl = sdl;
this.length = 0;
}
public Segment clone() {
Segment varCopy = new Segment();
public String comment() {
return this.comment;
}
varCopy.Length = this.Length;
varCopy.Comment = this.Comment;
varCopy.SDL = this.SDL;
public int length() {
return this.length;
}
return varCopy;
public String sdl() {
return this.sdl;
}
}

View File

@@ -43,7 +43,7 @@ public final class SegmentSerializer {
// If the RowBuffer isn't big enough to contain the rest of the header, then just
// return the length.
if (reader.get().length() < obj.get().Length) {
if (reader.get().length() < obj.get().length()) {
return Result.SUCCESS;
}
@@ -74,15 +74,15 @@ public final class SegmentSerializer {
public static Result Write(Reference<RowWriter> writer, TypeArgument typeArg, Segment obj) {
Result r;
if (obj.Comment != null) {
r = writer.get().WriteString("comment", obj.Comment);
if (obj.comment() != null) {
r = writer.get().WriteString("comment", obj.comment());
if (r != Result.SUCCESS) {
return r;
}
}
if (obj.SDL != null) {
r = writer.get().WriteString("sdl", obj.SDL);
if (obj.sdl() != null) {
r = writer.get().WriteString("sdl", obj.sdl());
if (r != Result.SUCCESS) {
return r;
}

View File

@@ -6,6 +6,7 @@ package com.azure.data.cosmos.serialization.hybridrow.schemas;
import com.azure.data.cosmos.core.Json;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
public class Namespace {
@@ -38,8 +39,9 @@ public class Namespace {
* Namespaces may consist of zero or more table schemas along with zero or more UDT schemas.
* Table schemas can only reference UDT schemas defined in the same namespace. UDT schemas can
* contain nested UDTs whose schemas are defined within the same namespace.
* @return
*/
public final ArrayList<Schema> schemas() {
public final List<Schema> schemas() {
return this.schemas;
}

View File

@@ -73,7 +73,7 @@ public class Schema {
checkNotNull(ns, "expected non-null ns");
checkArgument(ns.schemas().contains(this));
return LayoutCompiler.Compile(ns, this);
return LayoutCompiler.compile(ns, this);
}
/**

View File

@@ -32,7 +32,7 @@ public class BenchmarkSuiteBase {
//C# TO JAVA CONVERTER WARNING: Java has no equivalent to C# 'private protected' access:
//ORIGINAL LINE: private protected LayoutResolverNamespace DefaultResolver = (LayoutResolverNamespace)
// SystemSchema.LayoutResolver;
protected LayoutResolverNamespace DefaultResolver = (LayoutResolverNamespace)SystemSchema.LayoutResolver;
protected LayoutResolverNamespace DefaultResolver = (LayoutResolverNamespace)SystemSchema.layoutResolver;
// TODO: C# TO JAVA CONVERTER: Methods returning tuples are not converted by C# to Java Converter:
// private protected async Task<(List<Dictionary<Utf8String, object>>, LayoutResolverNamespace)>

View File

@@ -136,8 +136,8 @@ public class RecordIOUnitTests {
r = this.ReadSegment(segment, tempOut_obj);
obj = tempOut_obj.get();
ResultAssert.IsSuccess(r);
assert obj.Comment == sampleComment;
assert obj.SDL == sampleSDL;
assert obj.comment() == sampleComment;
assert obj.sdl() == sampleSDL;
return Result.SUCCESS;
}, resizer);

View File

@@ -54,7 +54,7 @@ public final class PostalCodeSerializer {
public static Result Write(Reference<RowWriter> writer, TypeArgument typeArg, PostalCode obj) {
Result r;
r = writer.get().WriteInt32("zip", obj.Zip);
r = writer.get().writeInt32("zip", obj.Zip);
if (r != Result.SUCCESS) {
return r;
}