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; private volatile T value;
public T get() { public T get() {
return value; return this.value;
} }
public void set(T 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} * @return {@code true} if there is a value present, otherwise {@code false}
*/ */
public boolean isPresent() { public boolean isPresent() {
return value != null; return this.value != null;
} }
/** /**
@@ -63,7 +63,7 @@ public final class Out<T> {
return false; 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 @Override
public int hashCode() { public int hashCode() {
return Objects.hashCode(value); return Objects.hashCode(this.value);
} }
@Override @Override
public String toString() { 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) { public RowBuffer(final int capacity, @Nonnull final ByteBufAllocator allocator) {
checkArgument(capacity > 0, "capacity: %s", capacity); checkArgument(capacity > 0, "capacity: %s", capacity);
checkNotNull(allocator, "allocator"); checkNotNull(allocator, "expected non-null allocator");
this.buffer = allocator.buffer(capacity); this.buffer = allocator.buffer(capacity);
this.resolver = null; this.resolver = null;
} }
@@ -308,9 +308,9 @@ public final class RowBuffer {
*/ */
public void initLayout(HybridRowVersion version, Layout layout, LayoutResolver resolver) { public void initLayout(HybridRowVersion version, Layout layout, LayoutResolver resolver) {
checkNotNull(version, "version"); checkNotNull(version, "expected non-null version");
checkNotNull(layout, "layout"); checkNotNull(layout, "expected non-null layout");
checkNotNull(resolver, "resolver"); checkNotNull(resolver, "expected non-null resolver");
this.writeHeader(new HybridRowHeader(version, layout.schemaId())); this.writeHeader(new HybridRowHeader(version, layout.schemaId()));
this.buffer.writeZero(layout.size()); 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) { @Nonnull final RowCursor edit, @Nonnull final LayoutScope scope, @Nonnull final UpdateOptions options) {
checkNotNull(edit, "expected non-null edit"); checkNotNull(edit, "expected non-null edit");
checkNotNull(scope, "expected non-null scopeType"); checkNotNull(scope, "expected non-null scope");
checkNotNull(options, "expected non-null options"); checkNotNull(options, "expected non-null options");
int length = LayoutCode.BYTES; int length = LayoutCode.BYTES;
@@ -2185,11 +2185,10 @@ public final class RowBuffer {
checkState(this.length() == priorLength + shift.get()); checkState(this.length() == priorLength + shift.get());
} }
public void writeVariableInt(int offset, long value, boolean exists, Out<Integer> shift) { public int writeVariableInt(int offset, long value, boolean exists) {
checkNotNull(shift, "expected non-null shift");
final int length = RowBuffer.count7BitEncodedInt(value); final int length = RowBuffer.count7BitEncodedInt(value);
final Out<Integer> shift = new Out<>();
final Out<Integer> spaceNeeded = new Out<>(); final Out<Integer> spaceNeeded = new Out<>();
final int priorLength = this.length(); final int priorLength = this.length();
@@ -2200,35 +2199,38 @@ public final class RowBuffer {
checkState(item.length == length); checkState(item.length == length);
checkState(spaceNeeded.get() == length); checkState(spaceNeeded.get() == length);
checkState(this.length() == priorLength + shift.get()); checkState(this.length() == priorLength + shift.get());
return shift.get();
} }
public void writeVariableString( public int writeVariableString(
final int offset, @Nonnull final Utf8String value, final boolean exists, @Nonnull final Out<Integer> shift) { final int offset, @Nonnull final Utf8String value, final boolean exists) {
checkNotNull(value, "expected non-null value"); checkNotNull(value, "expected non-null value");
checkNotNull(shift, "expected non-null shift");
checkArgument(!value.isNull(), "expected non-null value content"); checkArgument(!value.isNull(), "expected non-null value content");
checkArgument(offset >= 0, "expected non-negative offset, not %s", offset); checkArgument(offset >= 0, "expected non-negative offset, not %s", offset);
final int length = value.encodedLength(); final int length = value.encodedLength();
final Out<Integer> shift = new Out<>();
final Out<Integer> spaceNeeded = new Out<>(); final Out<Integer> spaceNeeded = new Out<>();
final int priorLength = this.length(); final int priorLength = this.length();
this.ensureVariable(offset, false, length, exists, spaceNeeded, shift); this.ensureVariable(offset, false, length, exists, spaceNeeded, shift);
Item<Utf8String> item = this.write(this::writeVariableString, offset, value); Item<Utf8String> item = this.write(this::writeVariableString, offset, value);
checkState(spaceNeeded.get() == length + item.length()); checkState(spaceNeeded.get() == length + item.length());
checkState(this.length() == priorLength + shift.get()); checkState(this.length() == priorLength + shift.get());
return shift.get();
} }
public void writeVariableUInt( public int writeVariableUInt(final int offset, final long value, final boolean exists) {
final int offset, final long value, final boolean exists, @Nonnull final Out<Integer> shift) {
checkNotNull(shift, "expected non-null shift");
checkArgument(offset >= 0, "expected non-negative offset, not %s", offset); checkArgument(offset >= 0, "expected non-negative offset, not %s", offset);
final int length = RowBuffer.count7BitEncodedUInt(value); final int length = RowBuffer.count7BitEncodedUInt(value);
final Out<Integer> shift = new Out<>();
final Out<Integer> spaceNeeded = new Out<>(); final Out<Integer> spaceNeeded = new Out<>();
final int priorLength = this.length(); final int priorLength = this.length();
@@ -2239,6 +2241,8 @@ public final class RowBuffer {
checkState(item.length == length); checkState(item.length == length);
checkState(spaceNeeded.get() == length); checkState(spaceNeeded.get() == length);
checkState(this.length() == priorLength + shift.get()); checkState(this.length() == priorLength + shift.get());
return shift.get();
} }
/** /**
@@ -2505,7 +2509,7 @@ public final class RowBuffer {
) { ) {
checkNotNull(edit, "expected non-null edit"); 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(typeArgs, "expected non-null typeArgs");
checkNotNull(options, "expected non-null options"); checkNotNull(options, "expected non-null options");
checkNotNull(metaBytes, "expected non-null metaBytes"); 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 //ORIGINAL LINE: return this.WritePrimitive(path, value, LayoutType.Binary, (ref RowWriter w, byte[] v) => w
// .row.WriteSparseBinary(ref w.cursor, v, UpdateOptions.Upsert)); // .row.WriteSparseBinary(ref w.cursor, v, UpdateOptions.Upsert));
return this.WritePrimitive(path, value, LayoutTypes.BINARY, 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, //ORIGINAL LINE: return this.WritePrimitive(path, value, LayoutType.Binary, (ref RowWriter w,
// ReadOnlySpan<byte> v) => w.row.WriteSparseBinary(ref w.cursor, v, UpdateOptions.Upsert)); // ReadOnlySpan<byte> v) => w.row.WriteSparseBinary(ref w.cursor, v, UpdateOptions.Upsert));
return this.WritePrimitive(path, value, LayoutType.Binary, 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)); // ReadOnlySequence<byte> v) => w.row.WriteSparseBinary(ref w.cursor, v, UpdateOptions.Upsert));
return this.WritePrimitive(path, value, LayoutType.Binary, return this.WritePrimitive(path, value, LayoutType.Binary,
(ref RowWriter w, ReadOnlySequence<Byte> v) -> w.row.WriteSparseBinary(ref w.cursor, v, (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 // 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: // cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.WritePrimitive(path, value, LayoutType.Boolean, 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 // 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: // cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.WritePrimitive(path, value, LayoutType.DateTime, 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 // 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: // cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.WritePrimitive(path, value, LayoutType.Decimal, 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 // 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: // 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, 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 // 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: // cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.WritePrimitive(path, value, LayoutType.Float32, 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 // 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: // cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.WritePrimitive(path, value, LayoutType.Float64, 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 // 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: // cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.WritePrimitive(path, value, LayoutType.Guid, 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 // 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: // cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.WritePrimitive(path, value, LayoutType.Int16, 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. * @param value The value to write.
* @return Success if the write is successful, an error code otherwise. * @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 // TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not
// converted by C# to Java Converter: // converted by C# to Java Converter:
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these // 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: // cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.WritePrimitive(path, value, LayoutType.Int32, 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 // 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: // cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.WritePrimitive(path, value, LayoutType.Int64, 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 // 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: // cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.WritePrimitive(path, value, LayoutType.Int8, 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 // 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: // 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, 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 // 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: // 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, 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, public <TContext> Result WriteScope(UtfAnyString path, TypeArgument typeArg, TContext context,
@@ -379,7 +379,7 @@ public final class RowWriter {
new Reference<RowCursor>(this.cursor); new Reference<RowCursor>(this.cursor);
Out<RowCursor> tempOut_nestedScope = Out<RowCursor> tempOut_nestedScope =
new Out<RowCursor>(); new Out<RowCursor>();
this.row.writeSparseObject(tempRef_cursor, scopeType, UpdateOptions.Upsert); this.row.writeSparseObject(tempRef_cursor, scopeType, UpdateOptions.UPSERT);
nestedScope = tempOut_nestedScope.get(); nestedScope = tempOut_nestedScope.get();
this.cursor = tempRef_cursor.argValue; this.cursor = tempRef_cursor.argValue;
break; break;
@@ -391,7 +391,7 @@ public final class RowWriter {
new Reference<RowCursor>(this.cursor); new Reference<RowCursor>(this.cursor);
Out<RowCursor> tempOut_nestedScope2 = Out<RowCursor> tempOut_nestedScope2 =
new Out<RowCursor>(); new Out<RowCursor>();
this.row.writeSparseArray(tempRef_cursor2, scopeType, UpdateOptions.Upsert); this.row.writeSparseArray(tempRef_cursor2, scopeType, UpdateOptions.UPSERT);
nestedScope = tempOut_nestedScope2.get(); nestedScope = tempOut_nestedScope2.get();
this.cursor = tempRef_cursor2.argValue; this.cursor = tempRef_cursor2.argValue;
break; break;
@@ -404,7 +404,7 @@ public final class RowWriter {
Out<RowCursor> tempOut_nestedScope3 = Out<RowCursor> tempOut_nestedScope3 =
new Out<RowCursor>(); new Out<RowCursor>();
this.row.writeTypedArray(tempRef_cursor3, scopeType, typeArg.typeArgs().clone(), this.row.writeTypedArray(tempRef_cursor3, scopeType, typeArg.typeArgs().clone(),
UpdateOptions.Upsert, tempOut_nestedScope3); UpdateOptions.UPSERT, tempOut_nestedScope3);
nestedScope = tempOut_nestedScope3.get(); nestedScope = tempOut_nestedScope3.get();
this.cursor = tempRef_cursor3.argValue; this.cursor = tempRef_cursor3.argValue;
@@ -418,7 +418,7 @@ public final class RowWriter {
Out<RowCursor> tempOut_nestedScope4 = Out<RowCursor> tempOut_nestedScope4 =
new Out<RowCursor>(); new Out<RowCursor>();
this.row.writeSparseTuple(tempRef_cursor4, scopeType, typeArg.typeArgs().clone(), this.row.writeSparseTuple(tempRef_cursor4, scopeType, typeArg.typeArgs().clone(),
UpdateOptions.Upsert, tempOut_nestedScope4); UpdateOptions.UPSERT, tempOut_nestedScope4);
nestedScope = tempOut_nestedScope4.get(); nestedScope = tempOut_nestedScope4.get();
this.cursor = tempRef_cursor4.argValue; this.cursor = tempRef_cursor4.argValue;
@@ -432,7 +432,7 @@ public final class RowWriter {
Out<RowCursor> tempOut_nestedScope5 = Out<RowCursor> tempOut_nestedScope5 =
new Out<RowCursor>(); new Out<RowCursor>();
this.row.writeTypedTuple(tempRef_cursor5, scopeType, typeArg.typeArgs().clone(), this.row.writeTypedTuple(tempRef_cursor5, scopeType, typeArg.typeArgs().clone(),
UpdateOptions.Upsert); UpdateOptions.UPSERT);
nestedScope = tempOut_nestedScope5.get(); nestedScope = tempOut_nestedScope5.get();
this.cursor = tempRef_cursor5.argValue; this.cursor = tempRef_cursor5.argValue;
@@ -446,7 +446,7 @@ public final class RowWriter {
Out<RowCursor> tempOut_nestedScope6 = Out<RowCursor> tempOut_nestedScope6 =
new Out<RowCursor>(); new Out<RowCursor>();
this.row.writeTypedTuple(tempRef_cursor6, scopeType, typeArg.typeArgs().clone(), this.row.writeTypedTuple(tempRef_cursor6, scopeType, typeArg.typeArgs().clone(),
UpdateOptions.Upsert); UpdateOptions.UPSERT);
nestedScope = tempOut_nestedScope6.get(); nestedScope = tempOut_nestedScope6.get();
this.cursor = tempRef_cursor6.argValue; this.cursor = tempRef_cursor6.argValue;
@@ -460,7 +460,7 @@ public final class RowWriter {
Out<RowCursor> tempOut_nestedScope7 = Out<RowCursor> tempOut_nestedScope7 =
new Out<RowCursor>(); new Out<RowCursor>();
this.row.writeTypedTuple(tempRef_cursor7, scopeType, typeArg.typeArgs().clone(), this.row.writeTypedTuple(tempRef_cursor7, scopeType, typeArg.typeArgs().clone(),
UpdateOptions.Upsert); UpdateOptions.UPSERT);
nestedScope = tempOut_nestedScope7.get(); nestedScope = tempOut_nestedScope7.get();
this.cursor = tempRef_cursor7.argValue; this.cursor = tempRef_cursor7.argValue;
@@ -474,7 +474,7 @@ public final class RowWriter {
Out<RowCursor> tempOut_nestedScope8 = Out<RowCursor> tempOut_nestedScope8 =
new Out<RowCursor>(); new Out<RowCursor>();
this.row.writeNullable(tempRef_cursor8, scopeType, typeArg.typeArgs().clone(), this.row.writeNullable(tempRef_cursor8, scopeType, typeArg.typeArgs().clone(),
UpdateOptions.Upsert, func != null); UpdateOptions.UPSERT, func != null);
nestedScope = tempOut_nestedScope8.get(); nestedScope = tempOut_nestedScope8.get();
this.cursor = tempRef_cursor8.argValue; this.cursor = tempRef_cursor8.argValue;
@@ -488,7 +488,7 @@ public final class RowWriter {
new Reference<RowCursor>(this.cursor); new Reference<RowCursor>(this.cursor);
Out<RowCursor> tempOut_nestedScope9 = Out<RowCursor> tempOut_nestedScope9 =
new Out<RowCursor>(); 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(); nestedScope = tempOut_nestedScope9.get();
this.cursor = tempReference_cursor9.get(); this.cursor = tempReference_cursor9.get();
break; break;
@@ -502,7 +502,7 @@ public final class RowWriter {
Out<RowCursor> tempOut_nestedScope10 = Out<RowCursor> tempOut_nestedScope10 =
new Out<RowCursor>(); new Out<RowCursor>();
this.row.writeTypedSet(tempRef_cursor10, scopeType, typeArg.typeArgs().clone(), this.row.writeTypedSet(tempRef_cursor10, scopeType, typeArg.typeArgs().clone(),
UpdateOptions.Upsert); UpdateOptions.UPSERT);
nestedScope = tempOut_nestedScope10.get(); nestedScope = tempOut_nestedScope10.get();
this.cursor = tempRef_cursor10.argValue; this.cursor = tempRef_cursor10.argValue;
@@ -516,7 +516,7 @@ public final class RowWriter {
Out<RowCursor> tempOut_nestedScope11 = Out<RowCursor> tempOut_nestedScope11 =
new Out<RowCursor>(); new Out<RowCursor>();
this.row.writeTypedMap(tempRef_cursor11, scopeType, typeArg.typeArgs().clone(), this.row.writeTypedMap(tempRef_cursor11, scopeType, typeArg.typeArgs().clone(),
UpdateOptions.Upsert); UpdateOptions.UPSERT);
nestedScope = tempOut_nestedScope11.get(); nestedScope = tempOut_nestedScope11.get();
this.cursor = tempRef_cursor11.argValue; 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: // cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.WritePrimitive(path, value, LayoutType.Utf8, return this.WritePrimitive(path, value, LayoutType.Utf8,
(ref RowWriter w, String v) -> w.row.WriteSparseString(ref w.cursor, Utf8Span.TranscodeUtf16(v), (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 // 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: // cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.WritePrimitive(path, value, LayoutType.Utf8, 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 //ORIGINAL LINE: return this.WritePrimitive(path, value, LayoutType.UInt16, (ref RowWriter w, ushort v) => w
// .row.WriteSparseUInt16(ref w.cursor, v, UpdateOptions.Upsert)); // .row.WriteSparseUInt16(ref w.cursor, v, UpdateOptions.Upsert));
return this.WritePrimitive(path, value, LayoutType.UInt16, 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: //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public Result WriteUInt32(UtfAnyString path, uint value) //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 // TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not
// converted by C# to Java Converter: // converted by C# to Java Converter:
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these // 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 //ORIGINAL LINE: return this.WritePrimitive(path, value, LayoutType.UInt32, (ref RowWriter w, uint v) => w
// .row.WriteSparseUInt32(ref w.cursor, v, UpdateOptions.Upsert)); // .row.WriteSparseUInt32(ref w.cursor, v, UpdateOptions.Upsert));
return this.WritePrimitive(path, value, LayoutType.UInt32, 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 //ORIGINAL LINE: return this.WritePrimitive(path, value, LayoutType.UInt64, (ref RowWriter w, ulong v) => w
// .row.WriteSparseUInt64(ref w.cursor, v, UpdateOptions.Upsert)); // .row.WriteSparseUInt64(ref w.cursor, v, UpdateOptions.Upsert));
return this.WritePrimitive(path, value, LayoutType.UInt64, 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 //ORIGINAL LINE: return this.WritePrimitive(path, value, LayoutType.UInt8, (ref RowWriter w, byte v) => w.row
// .WriteSparseUInt8(ref w.cursor, v, UpdateOptions.Upsert)); // .WriteSparseUInt8(ref w.cursor, v, UpdateOptions.Upsert));
return this.WritePrimitive(path, value, LayoutType.UInt8, 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: // 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, return this.WritePrimitive(path, value.clone(), LayoutType.UnixDateTime,
(ref RowWriter w, UnixDateTime v) -> w.row.WriteSparseUnixDateTime(ref w.cursor, v.clone(), (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 // 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: // cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.WritePrimitive(path, value, LayoutType.VarInt, 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 //ORIGINAL LINE: return this.WritePrimitive(path, value, LayoutType.VarUInt, (ref RowWriter w, ulong v) => w
// .row.WriteSparseVarUInt(ref w.cursor, v, UpdateOptions.Upsert)); // .row.WriteSparseVarUInt(ref w.cursor, v, UpdateOptions.Upsert));
return this.WritePrimitive(path, value, LayoutType.VarUInt, 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() { 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.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor; 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}. * An optional interface that indicates a {@link LayoutType{T}} can also read using a {@link Utf8String}.
*/ */
public interface ILayoutUtf8SpanReadable extends ILayoutType { 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.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor; 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} * An optional interface that indicates a {@link LayoutType{T}} can also write using a {@link Utf8String}
*/ */
public interface ILayoutUtf8SpanWritable extends ILayoutType { public interface ILayoutUtf8SpanWritable extends ILayoutType {
@Nonnull
Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Utf8String value); Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Utf8String value);
@Nonnull
Result writeSparse(RowBuffer buffer, RowCursor edit, Utf8String value); Result writeSparse(RowBuffer buffer, RowCursor edit, Utf8String value);
@Nonnull
Result writeSparse(RowBuffer buffer, RowCursor edit, Utf8String value, UpdateOptions options); Result writeSparse(RowBuffer buffer, RowCursor edit, Utf8String value, UpdateOptions options);
@Nonnull
Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, Utf8String value); 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 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 String name;
private final int numBitmaskBytes; 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); super(immutable ? IMMUTABLE_ARRAY_SCOPE : ARRAY_SCOPE, immutable, false, false, false, false);
} }
@Nonnull
public String name() { public String name() {
return this.isImmutable() ? "im_array" : "array"; return this.isImmutable() ? "im_array" : "array";
} }
@@ -30,7 +31,7 @@ public final class LayoutArray extends LayoutIndexedScope {
@Nonnull final RowCursor edit, @Nonnull final RowCursor edit,
@Nonnull final TypeArgumentList typeArgs, @Nonnull final TypeArgumentList typeArgs,
@Nonnull Out<RowCursor> value) { @Nonnull Out<RowCursor> value) {
return this.writeScope(buffer, edit, typeArgs, UpdateOptions.Upsert, value); return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value);
} }
@Override @Override

View File

@@ -4,11 +4,11 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts; package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out; 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.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor; import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull;
import java.util.List; import java.util.List;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
@@ -23,11 +23,17 @@ public final class LayoutBinary extends LayoutType<byte[]> implements ILayoutSpa
return false; return false;
} }
public Result WriteSparse(RowBuffer buffer, RowCursor edit, ReadOnlySequence<Byte> value) {
return writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
@Nonnull
public String name() { public String name() {
return "binary"; return "binary";
} }
@Override @Override
@Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<byte[]> value) { public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<byte[]> value) {
ReadOnlySpan<Byte> span; ReadOnlySpan<Byte> span;
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these // 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; 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(scope.scopeType() instanceof LayoutUDT);
checkArgument(column.size() >= 0); checkArgument(column.size() >= 0);
@@ -54,20 +60,6 @@ public final class LayoutBinary extends LayoutType<byte[]> implements ILayoutSpa
return Result.SUCCESS; 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: //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) //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) { 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: //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 //ORIGINAL LINE: public override Result ReadSparse(ref RowBuffer b, ref RowCursor edit, out byte[] value)
// byte[] value)
@Override @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; ReadOnlySpan<Byte> span;
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these // 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:
// 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: //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); //ORIGINAL LINE: Result r = this.ReadSparse(ref b, ref edit, out ReadOnlySpan<byte> span);
Result r = this.ReadVariable(buffer, scope, column, out span); Result r = this.ReadSparse(buffer, edit, out span);
value.set((r == Result.SUCCESS) ? span.ToArray() :) value.set((r == Result.SUCCESS) ? span.ToArray() :)
default default
return r; 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: //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[] //ORIGINAL LINE: public override Result ReadVariable(ref RowBuffer b, ref RowCursor scope, LayoutColumn col, out
// value) // byte[] value)
@Override @Override
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, byte[] value) { @Nonnull
checkArgument(value != null); public Result readVariable(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<byte[]> value) {
return this.writeFixed(buffer, scope, column, new ReadOnlySpan<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: //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; 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 @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) { 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: //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) // UpdateOptions options = UpdateOptions.Upsert)
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
@Override @Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, byte[] value, public Result writeSparse(RowBuffer buffer, RowCursor edit, byte[] value,
UpdateOptions options) { UpdateOptions options) {
checkArgument(value != null); 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); 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: //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, //ORIGINAL LINE: public Result WriteSparse(ref RowBuffer b, ref RowCursor edit, ReadOnlySpan<byte> value,
// UpdateOptions options = UpdateOptions.Upsert) // UpdateOptions options = UpdateOptions.Upsert)
@@ -197,32 +204,25 @@ public final class LayoutBinary extends LayoutType<byte[]> implements ILayoutSpa
return Result.SUCCESS; return Result.SUCCESS;
} }
public Result WriteSparse(RowBuffer b, RowCursor edit, ReadOnlySequence<Byte> value) { public Result writeSparse(RowBuffer buffer, RowCursor edit, Byte value) {
return writeSparse(b, edit, value, UpdateOptions.Upsert); return writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
} }
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above: public Result WriteSparse(RowBuffer buffer, RowCursor edit, ReadOnlySequence<Byte> value, UpdateOptions options) {
//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) {
Result result = LayoutType.prepareSparseWrite(b, edit, this.typeArg(), options); Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options);
if (result != Result.SUCCESS) { if (result != Result.SUCCESS) {
return result; return result;
} }
b.writeSparseBinary(edit, value, options); buffer.writeSparseBinary(edit, value, options);
return Result.SUCCESS; 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 @Override
public Result writeVariable(RowBuffer buffer, RowCursor scope, @Nonnull
LayoutColumn column, byte[] value) { public Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, byte[] value) {
checkArgument(value != null); checkArgument(value != null);
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: //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)); //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 @Override
@Nonnull
public String name() { public String name() {
return "bool"; return "bool";
} }
@@ -133,7 +134,8 @@ public final class LayoutBoolean extends LayoutType<Boolean> {
} }
@Override @Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Boolean value) { 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.TuplePropertyType;
import com.azure.data.cosmos.serialization.hybridrow.schemas.TypeKind; import com.azure.data.cosmos.serialization.hybridrow.schemas.TypeKind;
import com.azure.data.cosmos.serialization.hybridrow.schemas.UdtPropertyType; import com.azure.data.cosmos.serialization.hybridrow.schemas.UdtPropertyType;
import com.google.common.base.Strings;
import tangible.ListHelper; import tangible.ListHelper;
import javax.annotation.Nonnull;
import java.util.List; import java.util.List;
import java.util.Optional;
import static com.google.common.base.Preconditions.checkArgument; 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. * Converts a logical schema into a physical layout.
*/ */
public final class LayoutCompiler { 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 ns The namespace within which {@code schema} is defined
* @param schema The logical schema to produce a layout for. * @param schema The logical schema to produce a layout for
* @return The layout for the schema. * @return The layout for the schema
*/ */
public static Layout Compile(Namespace ns, Schema schema) { @Nonnull
checkArgument(ns != null); public static Layout compile(@Nonnull final Namespace ns, @Nonnull final Schema schema) {
checkArgument(schema != null);
checkNotNull(ns, "expected non-null ns");
checkNotNull(schema, "expected non-null schema");
checkArgument(schema.type() == TypeKind.Schema); checkArgument(schema.type() == TypeKind.Schema);
checkArgument(!tangible.StringHelper.isNullOrWhiteSpace(schema.name())); checkArgument(!Strings.isNullOrEmpty(schema.name()));
checkArgument(ns.schemas().contains(schema)); checkArgument(ns.schemas().contains(schema));
LayoutBuilder builder = new LayoutBuilder(schema.name(), schema.schemaId()); LayoutBuilder builder = new LayoutBuilder(schema.name(), schema.schemaId());
@@ -63,7 +70,6 @@ public final class LayoutCompiler {
if (!p.propertyType().nullable()) { if (!p.propertyType().nullable()) {
throw new LayoutCompilationException("Non-nullable sparse column are not supported."); throw new LayoutCompilationException("Non-nullable sparse column are not supported.");
} }
ObjectPropertyType op = (ObjectPropertyType)p.propertyType(); ObjectPropertyType op = (ObjectPropertyType)p.propertyType();
builder.addObjectScope(p.path(), type); builder.addObjectScope(p.path(), type);
LayoutCompiler.addProperties(builder, ns, type.layoutCode(), op.properties()); LayoutCompiler.addProperties(builder, ns, type.layoutCode(), op.properties());
@@ -94,52 +100,52 @@ public final class LayoutCompiler {
} }
default: { default: {
PropertyType tempVar = p.propertyType();
PrimitivePropertyType pp = tempVar instanceof PrimitivePropertyType ? if (p.propertyType() instanceof PrimitivePropertyType) {
(PrimitivePropertyType)tempVar : null;
if (pp != null) { PrimitivePropertyType pp = (PrimitivePropertyType) p.propertyType();
switch (pp.storage()) { switch (pp.storage()) {
case FIXED: case FIXED:
if (LayoutCodeTraits.clearImmutableBit(scope) != LayoutCode.SCHEMA) { if (LayoutCodeTraits.clearImmutableBit(scope) != LayoutCode.SCHEMA) {
throw new LayoutCompilationException("Cannot have fixed storage within a sparse " + throw new LayoutCompilationException(
"scope."); "Cannot have fixed storage within a sparse scope.");
} }
if (type.isNull() && !pp.nullable()) { 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()); builder.addFixedColumn(p.path(), type, pp.nullable(), pp.length());
break; break;
case VARIABLE: case VARIABLE:
if (LayoutCodeTraits.clearImmutableBit(scope) != LayoutCode.SCHEMA) { if (LayoutCodeTraits.clearImmutableBit(scope) != LayoutCode.SCHEMA) {
throw new LayoutCompilationException("Cannot have variable storage within a " + throw new LayoutCompilationException(
"sparse scope."); "Cannot have variable storage within a sparse scope.");
} }
if (!pp.nullable()) { if (!pp.nullable()) {
throw new LayoutCompilationException("Non-nullable variable columns are not " + throw new LayoutCompilationException(
"supported."); "Non-nullable variable columns are not supported.");
} }
builder.addVariableColumn(p.path(), type, pp.length()); builder.addVariableColumn(p.path(), type, pp.length());
break; break;
case SPARSE: case SPARSE:
if (!pp.nullable()) { if (!pp.nullable()) {
throw new LayoutCompilationException("Non-nullable sparse columns are not " + throw new LayoutCompilationException(
"supported."); "Non-nullable sparse columns are not supported.");
} }
builder.addSparseColumn(p.path(), type); builder.addSparseColumn(p.path(), type);
break; break;
default: default:
throw new LayoutCompilationException(String.format("Unknown storage specification: " + throw new LayoutCompilationException(
"%1$s", pp.storage())); lenientFormat("Unknown storage specification: %s", pp.storage()));
} }
} else { } else {
throw new LayoutCompilationException(String.format("Unknown property type: %1$s", throw new LayoutCompilationException(
type.name())); lenientFormat("Unknown property type: %s", type.name()));
} }
break; break;
@@ -150,152 +156,187 @@ public final class LayoutCompiler {
private static LayoutType logicalToPhysicalType(Namespace ns, PropertyType logicalType, private static LayoutType logicalToPhysicalType(Namespace ns, PropertyType logicalType,
Out<TypeArgumentList> typeArgs) { Out<TypeArgumentList> typeArgs) {
typeArgs.setAndGet(TypeArgumentList.EMPTY);
boolean tempVar = typeArgs.set(TypeArgumentList.EMPTY);
(logicalType instanceof ScopePropertyType ? (ScopePropertyType)logicalType : null).immutable(); boolean immutable = logicalType instanceof ScopePropertyType && ((ScopePropertyType) logicalType).immutable();
boolean immutable =
(logicalType instanceof ScopePropertyType ? (ScopePropertyType)logicalType : null) == null ? null :
tempVar != null && tempVar;
switch (logicalType.type()) { switch (logicalType.type()) {
case Null: case Null:
return LayoutTypes.NULL; return LayoutTypes.NULL;
case Boolean: case Boolean:
return LayoutTypes.BOOLEAN; return LayoutTypes.BOOLEAN;
case Int8: case Int8:
return LayoutTypes.INT_8; return LayoutTypes.INT_8;
case Int16: case Int16:
return LayoutTypes.INT_16; return LayoutTypes.INT_16;
case Int32: case Int32:
return LayoutTypes.INT_32; return LayoutTypes.INT_32;
case Int64: case Int64:
return LayoutTypes.INT_64; return LayoutTypes.INT_64;
case UInt8: case UInt8:
return LayoutTypes.UINT_8; return LayoutTypes.UINT_8;
case UInt16: case UInt16:
return LayoutTypes.UINT_16; return LayoutTypes.UINT_16;
case UInt32: case UInt32:
return LayoutTypes.UINT_32; return LayoutTypes.UINT_32;
case UInt64: case UInt64:
return LayoutTypes.UINT_64; return LayoutTypes.UINT_64;
case Float32: case Float32:
return LayoutTypes.FLOAT_32; return LayoutTypes.FLOAT_32;
case Float64: case Float64:
return LayoutTypes.FLOAT_64; return LayoutTypes.FLOAT_64;
case Float128: case Float128:
return LayoutTypes.FLOAT_128; return LayoutTypes.FLOAT_128;
case Decimal: case Decimal:
return LayoutTypes.DECIMAL; return LayoutTypes.DECIMAL;
case DateTime: case DateTime:
return LayoutTypes.DATE_TIME; return LayoutTypes.DATE_TIME;
case UnixDateTime: case UnixDateTime:
return LayoutTypes.UNIX_DATE_TIME; return LayoutTypes.UNIX_DATE_TIME;
case Guid: case Guid:
return LayoutTypes.GUID; return LayoutTypes.GUID;
case MongoDbObjectId: case MongoDbObjectId:
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
// return LayoutTypes.MONGO_DB_OBJECT_ID; // return LayoutTypes.MONGO_DB_OBJECT_ID;
case Utf8: case Utf8:
return LayoutTypes.UTF_8; return LayoutTypes.UTF_8;
case Binary: case Binary:
return LayoutTypes.BINARY; return LayoutTypes.BINARY;
case VarInt: case VarInt:
return LayoutTypes.VAR_INT; return LayoutTypes.VAR_INT;
case VarUInt: case VarUInt:
return LayoutTypes.VAR_UINT; return LayoutTypes.VAR_UINT;
case Object: case Object:
return immutable ? LayoutTypes.IMMUTABLE_OBJECT : LayoutTypes.OBJECT; return immutable ? LayoutTypes.IMMUTABLE_OBJECT : LayoutTypes.OBJECT;
case Array:
ArrayPropertyType ap = (ArrayPropertyType)logicalType; case Array: {
if ((ap.items() != null) && (ap.items().type() != TypeKind.Any)) {
TypeArgumentList itemTypeArgs = new TypeArgumentList(); assert logicalType instanceof ArrayPropertyType;
Out<TypeArgumentList> tempOut_itemTypeArgs = new Out<TypeArgumentList>(); ArrayPropertyType ap = (ArrayPropertyType) logicalType;
LayoutType itemType = LayoutCompiler.logicalToPhysicalType(ns, ap.items(), tempOut_itemTypeArgs);
itemTypeArgs = tempOut_itemTypeArgs.get(); 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()) { if (ap.items().nullable()) {
itemTypeArgs = new TypeArgumentList(new TypeArgument[] { new TypeArgument(itemType, itemTypeArgs = new TypeArgumentList(new TypeArgument(itemType, itemTypeArgs));
itemTypeArgs) });
itemType = itemType.isImmutable() ? LayoutTypes.IMMUTABLE_NULLABLE : LayoutTypes.NULLABLE; itemType = itemType.isImmutable() ? LayoutTypes.IMMUTABLE_NULLABLE : LayoutTypes.NULLABLE;
} }
typeArgs.setAndGet(new TypeArgumentList(new TypeArgument[] { new TypeArgument(itemType, typeArgs.set(new TypeArgumentList(new TypeArgument(itemType, itemTypeArgs)));
itemTypeArgs) }));
return immutable ? LayoutTypes.IMMUTABLE_TYPED_ARRAY : LayoutTypes.TYPED_ARRAY; return immutable ? LayoutTypes.IMMUTABLE_TYPED_ARRAY : LayoutTypes.TYPED_ARRAY;
} }
return immutable ? LayoutTypes.IMMUTABLE_ARRAY : LayoutTypes.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)) { if ((sp.items() != null) && (sp.items().type() != TypeKind.Any)) {
TypeArgumentList itemTypeArgs = new TypeArgumentList();
Out<TypeArgumentList> tempOut_itemTypeArgs2 = new Out<TypeArgumentList>(); final Out<TypeArgumentList> out = new Out<>();
LayoutType itemType = LayoutCompiler.logicalToPhysicalType(ns, sp.items(),
tempOut_itemTypeArgs2); LayoutType itemType = LayoutCompiler.logicalToPhysicalType(ns, sp.items(), out);
itemTypeArgs = tempOut_itemTypeArgs2.get(); TypeArgumentList itemTypeArgs = out.get();
if (sp.items().nullable()) { if (sp.items().nullable()) {
itemTypeArgs = new TypeArgumentList(new TypeArgument[] { new TypeArgument(itemType, itemTypeArgs = new TypeArgumentList(new TypeArgument(itemType, itemTypeArgs));
itemTypeArgs) });
itemType = itemType.isImmutable() ? LayoutTypes.IMMUTABLE_NULLABLE : LayoutTypes.NULLABLE; itemType = itemType.isImmutable() ? LayoutTypes.IMMUTABLE_NULLABLE : LayoutTypes.NULLABLE;
} }
typeArgs.setAndGet(new TypeArgumentList(new TypeArgument[] { new TypeArgument(itemType, typeArgs.set(new TypeArgumentList(new TypeArgument(itemType, itemTypeArgs)));
itemTypeArgs) }));
return immutable ? LayoutTypes.IMMUTABLE_TYPED_SET : LayoutTypes.TYPED_SET; return immutable ? LayoutTypes.IMMUTABLE_TYPED_SET : LayoutTypes.TYPED_SET;
} }
// TODO(283638): implement sparse set. // TODO(283638): implement sparse set
throw new LayoutCompilationException(String.format("Unknown property type: %1$s",
logicalType.type())); 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()) { if (mp.keys().nullable()) {
keyTypeArgs = new TypeArgumentList(new TypeArgument[] { new TypeArgument(keyType, keyTypeArgs = new TypeArgumentList(new TypeArgument(keyType, keyTypeArgs));
keyTypeArgs) });
keyType = keyType.isImmutable() ? LayoutTypes.IMMUTABLE_NULLABLE : LayoutTypes.NULLABLE; keyType = keyType.isImmutable() ? LayoutTypes.IMMUTABLE_NULLABLE : LayoutTypes.NULLABLE;
} }
TypeArgumentList valueTypeArgs = new TypeArgumentList(); LayoutType valueType = LayoutCompiler.logicalToPhysicalType(ns, mp.values(), out);
Out<TypeArgumentList> tempOut_valueTypeArgs = new Out<TypeArgumentList>(); TypeArgumentList valueTypeArgs = out.get();
LayoutType valueType = LayoutCompiler.logicalToPhysicalType(ns, mp.values(),
tempOut_valueTypeArgs);
valueTypeArgs = tempOut_valueTypeArgs.get();
if (mp.values().nullable()) { if (mp.values().nullable()) {
valueTypeArgs = new TypeArgumentList(new TypeArgument[] { new TypeArgument(valueType, valueTypeArgs = new TypeArgumentList(new TypeArgument(valueType, valueTypeArgs));
valueTypeArgs) });
valueType = valueType.isImmutable() ? LayoutTypes.IMMUTABLE_NULLABLE : LayoutTypes.NULLABLE; valueType = valueType.isImmutable() ? LayoutTypes.IMMUTABLE_NULLABLE : LayoutTypes.NULLABLE;
} }
typeArgs.setAndGet(new TypeArgumentList(new TypeArgument[] typeArgs.set(new TypeArgumentList(
{ new TypeArgument(keyType, keyTypeArgs),
new TypeArgument(keyType, keyTypeArgs), new TypeArgument(valueType, valueTypeArgs)
new TypeArgument(valueType, valueTypeArgs) ));
}));
return immutable ? LayoutTypes.IMMUTABLE_TYPED_MAP : LayoutTypes.TYPED_MAP; return immutable ? LayoutTypes.IMMUTABLE_TYPED_MAP : LayoutTypes.TYPED_MAP;
} }
// TODO(283638): implement sparse map. // TODO(283638): implement sparse map
throw new LayoutCompilationException(String.format("Unknown property type: %1$s",
logicalType.type())); 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++) { 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), out);
LayoutType itemType = LayoutCompiler.logicalToPhysicalType(ns, tp.items().get(i), TypeArgumentList itemTypeArgs = out.get();
tempOut_itemTypeArgs3);
itemTypeArgs = tempOut_itemTypeArgs3.get();
if (tp.items().get(i).nullable()) { if (tp.items().get(i).nullable()) {
itemTypeArgs = new TypeArgumentList(new TypeArgument[] { new TypeArgument(itemType, itemTypeArgs = new TypeArgumentList(new TypeArgument(itemType, itemTypeArgs));
itemTypeArgs) });
itemType = itemType.isImmutable() ? LayoutTypes.IMMUTABLE_NULLABLE : LayoutTypes.NULLABLE; itemType = itemType.isImmutable() ? LayoutTypes.IMMUTABLE_NULLABLE : LayoutTypes.NULLABLE;
} }
@@ -304,33 +345,41 @@ public final class LayoutCompiler {
typeArgs.setAndGet(new TypeArgumentList(args)); typeArgs.setAndGet(new TypeArgumentList(args));
return immutable ? LayoutTypes.IMMUTABLE_TYPED_TUPLE : LayoutTypes.TYPED_TUPLE; return immutable ? LayoutTypes.IMMUTABLE_TYPED_TUPLE : LayoutTypes.TYPED_TUPLE;
}
case TAGGED: {
case TAGGED: assert logicalType instanceof TaggedPropertyType;
TaggedPropertyType tg = (TaggedPropertyType)logicalType; 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 " + if (tg.items().size() < TaggedPropertyType.MinTaggedArguments || (tg.items().size() > TaggedPropertyType.MaxTaggedArguments)) {
"<= %2$s <= %3$s", TaggedPropertyType.MinTaggedArguments, tg.items().size(), throw new LayoutCompilationException(lenientFormat(
TaggedPropertyType.MaxTaggedArguments)); "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); tgArgs[0] = new TypeArgument(LayoutTypes.UINT_8, TypeArgumentList.EMPTY);
for (int i = 0; i < tg.items().size(); i++) { 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), out);
LayoutType itemType = LayoutCompiler.logicalToPhysicalType(ns, tg.items().get(i), TypeArgumentList itemTypeArgs = out.get();
tempOut_itemTypeArgs4);
itemTypeArgs = tempOut_itemTypeArgs4.get();
if (tg.items().get(i).nullable()) { if (tg.items().get(i).nullable()) {
itemTypeArgs = new TypeArgumentList(new TypeArgument[] { new TypeArgument(itemType, itemTypeArgs = new TypeArgumentList(new TypeArgument(itemType, itemTypeArgs));
itemTypeArgs) });
itemType = itemType.isImmutable() ? LayoutTypes.IMMUTABLE_NULLABLE : LayoutTypes.NULLABLE; itemType = itemType.isImmutable() ? LayoutTypes.IMMUTABLE_NULLABLE : LayoutTypes.NULLABLE;
} }
tgArgs[i + 1] = new TypeArgument(itemType, itemTypeArgs); tgArgs[i + 1] = new TypeArgument(itemType, itemTypeArgs);
} }
typeArgs.setAndGet(new TypeArgumentList(tgArgs)); typeArgs.set(new TypeArgumentList(tgArgs));
switch (tg.items().size()) { switch (tg.items().size()) {
case 1: case 1:
return immutable ? LayoutTypes.IMMUTABLE_TAGGED : LayoutTypes.TAGGED; return immutable ? LayoutTypes.IMMUTABLE_TAGGED : LayoutTypes.TAGGED;
@@ -339,32 +388,42 @@ public final class LayoutCompiler {
default: default:
throw new LayoutCompilationException("Unexpected tagged arity"); throw new LayoutCompilationException("Unexpected tagged arity");
} }
}
case Schema: {
case Schema: assert logicalType instanceof UdtPropertyType;
UdtPropertyType up = (UdtPropertyType)logicalType; UdtPropertyType up = (UdtPropertyType) logicalType;
Schema udtSchema;
if (SchemaId.opEquals(up.schemaId(), SchemaId.INVALID)) { final Optional<Schema> udtSchema;
udtSchema = ListHelper.find(ns.schemas(), s = up.name().equals( > s.Name))
if (up.schemaId() == SchemaId.INVALID) {
udtSchema = ns.schemas().stream()
.filter(schema -> up.name().equals(schema.name()))
.findFirst();
} else { } else {
udtSchema = ListHelper.find(ns.schemas(), s = udtSchema = ns.schemas().stream()
SchemaId.opEquals( > s.SchemaId, up.schemaId())) .filter(schema -> up.schemaId().equals(schema.schemaId()))
if (!udtSchema.name().equals(up.name())) { .findFirst();
throw new LayoutCompilationException(String.format("Ambiguous schema reference: '%1$s:%2$s'", if (up.name().equals(udtSchema.map(Schema::name).orElse(null))) {
up.name(), up.schemaId())); throw new LayoutCompilationException(lenientFormat(
"Ambiguous schema reference: '%s:%s'", up.name(), up.schemaId()
));
} }
} }
if (udtSchema == null) { if (!udtSchema.isPresent()) {
throw new LayoutCompilationException(String.format("Cannot resolve schema reference '%1$s:%2$s'", throw new LayoutCompilationException(lenientFormat(
up.name(), up.schemaId())); "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; return immutable ? LayoutTypes.IMMUTABLE_UDT : LayoutTypes.UDT;
}
default: default:
throw new LayoutCompilationException(String.format("Unknown property type: %1$s", throw new LayoutCompilationException(Strings.lenientFormat(
logicalType.type())); "Unknown property type: %s", logicalType.type()
));
} }
} }
} }

View File

@@ -4,14 +4,12 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts; package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out; 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.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor; import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import com.azure.data.cosmos.serialization.hybridrow.codecs.DateTimeCodec; import com.azure.data.cosmos.serialization.hybridrow.codecs.DateTimeCodec;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.time.LocalDateTime;
import java.time.OffsetDateTime; import java.time.OffsetDateTime;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
@@ -26,6 +24,7 @@ public final class LayoutDateTime extends LayoutType<OffsetDateTime> {
return true; return true;
} }
@Nonnull
public String name() { public String name() {
return "datetime"; return "datetime";
} }
@@ -77,20 +76,21 @@ public final class LayoutDateTime extends LayoutType<OffsetDateTime> {
@Override @Override
@Nonnull @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) { if (result != Result.SUCCESS) {
return result; return result;
} }
b.writeSparseDateTime(edit, value, options); buffer.writeSparseDateTime(edit, value, options);
return Result.SUCCESS; return Result.SUCCESS;
} }
@Override @Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, OffsetDateTime value) { 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; return true;
} }
@Nonnull
public String name() { public String name() {
return "decimal"; return "decimal";
} }
@@ -86,6 +87,6 @@ public final class LayoutDecimal extends LayoutType<BigDecimal> {
@Override @Override
@Nonnull @Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, BigDecimal value) { 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); super(LayoutCode.END_SCOPE, false, false, false, false, false, false);
} }
@Nonnull
public String name() { public String name() {
return "end"; return "end";
} }
@Override @Override
@Nonnull @Nonnull
public Result writeScope(RowBuffer buffer, RowCursor scope, TypeArgumentList typeArgs, Out<RowCursor> value) { public Result writeScope(
return this.writeScope(buffer, scope, typeArgs, UpdateOptions.Upsert, value); @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 @Override
@Nonnull @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"; assert false : "cannot write an EndScope directly";
value.set(null); value.set(null);
return Result.FAILURE; return Result.FAILURE;
} }
} }

View File

@@ -23,6 +23,7 @@ public final class LayoutFloat128 extends LayoutType<Float128> {
return true; return true;
} }
@Nonnull
public String name() { public String name() {
return "float128"; return "float128";
} }
@@ -89,6 +90,6 @@ public final class LayoutFloat128 extends LayoutType<Float128> {
@Override @Override
@Nonnull @Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Float128 value) { 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; package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out; 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.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor; import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
@@ -23,6 +22,7 @@ public final class LayoutFloat32 extends LayoutType<Float> {
return true; return true;
} }
@Nonnull
public String name() { public String name() {
return "float32"; return "float32";
} }
@@ -89,6 +89,6 @@ public final class LayoutFloat32 extends LayoutType<Float> {
@Override @Override
@Nonnull @Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Float value) { 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; return true;
} }
@Nonnull
public String name() { public String name() {
return "float64"; return "float64";
} }
@@ -91,6 +92,6 @@ public final class LayoutFloat64 extends LayoutType<Double> {
@Override @Override
@Nonnull @Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Double value) { 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; return true;
} }
@Nonnull
public String name() { public String name() {
return "guid"; return "guid";
} }
@@ -90,6 +91,6 @@ public final class LayoutGuid extends LayoutType<UUID> {
@Override @Override
@Nonnull @Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, UUID value) { 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 @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.pathToken(0);
edit.pathOffset(0); edit.pathOffset(0);
} }

View File

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

View File

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

View File

@@ -22,6 +22,7 @@ public final class LayoutInt8 extends LayoutType<Byte> {
return true; return true;
} }
@Nonnull
public String name() { public String name() {
return "int8"; return "int8";
} }
@@ -88,6 +89,6 @@ public final class LayoutInt8 extends LayoutType<Byte> {
@Override @Override
@Nonnull @Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Byte value) { 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.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor; 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.checkArgument;
public final class LayoutMongoDbObjectId extends LayoutType<MongoDbObjectId> { public final class LayoutMongoDbObjectId extends LayoutType<MongoDbObjectId> {
@@ -20,11 +22,13 @@ public final class LayoutMongoDbObjectId extends LayoutType<MongoDbObjectId> {
} }
// ReSharper disable once StringLiteralTypo // ReSharper disable once StringLiteralTypo
@Nonnull
public String name() { public String name() {
return "mongodbobjectid"; return "mongodbobjectid";
} }
@Override @Override
@Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column,
Out<MongoDbObjectId> value) { Out<MongoDbObjectId> value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT); checkArgument(scope.get().scopeType() instanceof LayoutUDT);
@@ -38,9 +42,10 @@ public final class LayoutMongoDbObjectId extends LayoutType<MongoDbObjectId> {
} }
@Override @Override
@Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, public Result readSparse(RowBuffer buffer, RowCursor edit,
Out<MongoDbObjectId> value) { Out<MongoDbObjectId> value) {
Result result = LayoutType.prepareSparseRead(buffer, edit, this.LayoutCode); Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode());
if (result != Result.SUCCESS) { if (result != Result.SUCCESS) {
value.setAndGet(null); value.setAndGet(null);
return result; return result;
@@ -51,6 +56,7 @@ public final class LayoutMongoDbObjectId extends LayoutType<MongoDbObjectId> {
} }
@Override @Override
@Nonnull
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column,
MongoDbObjectId value) { MongoDbObjectId value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT); 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, //ORIGINAL LINE: public override Result WriteSparse(ref RowBuffer b, ref RowCursor edit, MongoDbObjectId value,
// UpdateOptions options = UpdateOptions.Upsert) // UpdateOptions options = UpdateOptions.Upsert)
@Override @Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, public Result writeSparse(RowBuffer buffer, RowCursor edit,
MongoDbObjectId value, UpdateOptions options) { MongoDbObjectId value, UpdateOptions options) {
Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg().clone(), options); Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg().clone(), options);
@@ -79,8 +86,9 @@ public final class LayoutMongoDbObjectId extends LayoutType<MongoDbObjectId> {
} }
@Override @Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, public Result writeSparse(RowBuffer buffer, RowCursor edit,
MongoDbObjectId value) { 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.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor; 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.checkArgument;
public final class LayoutNull extends LayoutType<NullValue> { public final class LayoutNull extends LayoutType<NullValue> {
public LayoutNull() { public LayoutNull() {
super(com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.NULL, 0); super(LayoutCode.NULL, 0);
} }
public boolean isFixed() { public boolean isFixed() {
@@ -24,64 +27,59 @@ public final class LayoutNull extends LayoutType<NullValue> {
return true; return true;
} }
@Nonnull
public String name() { public String name() {
return "null"; return "null";
} }
@Override @Override
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, @Nonnull
Out<NullValue> value) { public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<NullValue> value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT); checkArgument(scope.scopeType() instanceof LayoutUDT);
value.setAndGet(NullValue.Default); value.set(NullValue.Default);
if (!buffer.get().readBit(scope.get().start(), column.getNullBit().clone())) { if (!buffer.readBit(scope.start(), column.nullBit())) {
return Result.NOT_FOUND; return Result.NOT_FOUND;
} }
return Result.SUCCESS; return Result.SUCCESS;
} }
@Override @Override
public Result readSparse(RowBuffer buffer, RowCursor edit, @Nonnull
Out<NullValue> value) { public Result readSparse(RowBuffer buffer, RowCursor edit, Out<NullValue> value) {
Result result = prepareSparseRead(buffer, edit, this.LayoutCode); Result result = prepareSparseRead(buffer, edit, this.layoutCode());
if (result != Result.SUCCESS) { if (result != Result.SUCCESS) {
value.setAndGet(null); value.set(null);
return result; return result;
} }
value.set(buffer.readSparseNull(edit));
value.setAndGet(buffer.get().readSparseNull(edit).clone());
return Result.SUCCESS; return Result.SUCCESS;
} }
@Override @Override
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, @Nonnull
NullValue value) { public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, NullValue value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT); checkArgument(scope.scopeType() instanceof LayoutUDT);
if (scope.get().immutable()) { if (scope.immutable()) {
return Result.INSUFFICIENT_PERMISSIONS; return Result.INSUFFICIENT_PERMISSIONS;
} }
buffer.setBit(scope.start(), column.nullBit());
buffer.get().SetBit(scope.get().start(), column.getNullBit().clone());
return Result.SUCCESS; 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 @Override
public Result writeSparse(RowBuffer buffer, RowCursor edit, NullValue value, @Nonnull
UpdateOptions options) { public Result writeSparse(RowBuffer buffer, RowCursor edit, NullValue value, UpdateOptions options) {
Result result = prepareSparseWrite(buffer, edit, this.typeArg().clone(), options); Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options);
if (result != Result.SUCCESS) { if (result != Result.SUCCESS) {
return result; return result;
} }
buffer.writeSparseNull(edit, value, options);
buffer.get().WriteSparseNull(edit, value.clone(), options);
return Result.SUCCESS; return Result.SUCCESS;
} }
@Override @Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, NullValue value) { 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; package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out; 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.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor; 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; import static com.google.common.base.Preconditions.checkState;
public final class LayoutNullable extends LayoutIndexedScope { public final class LayoutNullable extends LayoutIndexedScope {
public LayoutNullable(boolean immutable) { public LayoutNullable(boolean immutable) {
super(immutable ? com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.IMMUTABLE_NULLABLE_SCOPE : super(
com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.NULLABLE_SCOPE, immutable, true, true, false, true); immutable ? LayoutCode.IMMUTABLE_NULLABLE_SCOPE : LayoutCode.NULLABLE_SCOPE, immutable,
} true, true, false, true
);
public String name() {
return this.Immutable ? "im_nullable" : "nullable";
} }
@Override
public int countTypeArgument(@Nonnull final TypeArgumentList value) { public int countTypeArgument(@Nonnull final TypeArgumentList value) {
checkNotNull(value, "expected non-null value"); checkNotNull(value, "expected non-null value");
checkArgument(value.count() == 1); 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 @Override
@@ -40,72 +45,94 @@ public final class LayoutNullable extends LayoutIndexedScope {
return !LayoutCodeTraits.alwaysRequiresTypeCode(edit.scopeTypeArgs().get(0).type().layoutCode()); return !LayoutCodeTraits.alwaysRequiresTypeCode(edit.scopeTypeArgs().get(0).type().layoutCode());
} }
public static Result hasValue(@Nonnull final RowBuffer b, @Nonnull final RowCursor scope) { public static Result hasValue(@Nonnull final RowBuffer buffer, @Nonnull final RowCursor scope) {
checkNotNull(b); checkNotNull(buffer);
checkNotNull(scope); checkNotNull(scope);
checkArgument(scope.scopeType() instanceof LayoutNullable); checkArgument(scope.scopeType() instanceof LayoutNullable);
checkArgument(scope.index() == 1 || scope.index() == 2); checkArgument(scope.index() == 1 || scope.index() == 2);
checkArgument(scope.scopeTypeArgs().count() == 1); 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; return hasValue ? Result.SUCCESS : Result.NOT_FOUND;
} }
@Override @Override
public TypeArgumentList readTypeArgumentList( public TypeArgumentList readTypeArgumentList(
@Nonnull final RowBuffer row, int offset, @Nonnull final Out<Integer> lenInBytes) { @Nonnull final RowBuffer buffer, final int offset, @Nonnull final Out<Integer> lengthInBytes) {
return new TypeArgumentList(LayoutType.readTypeArgument(row, offset, lenInBytes)); return new TypeArgumentList(LayoutType.readTypeArgument(buffer, offset, lengthInBytes));
} }
@Override @Override
public void setImplicitTypeCode(RowCursor edit) { public void setImplicitTypeCode(RowCursor edit) {
checkState(edit.index() == 1); checkState(edit.index() == 1);
edit.get().cellType(edit.get().scopeTypeArgs().get(0).type()); edit.cellType(edit.scopeTypeArgs().get(0).type());
edit.get().cellTypeArgs(edit.get().scopeTypeArgs().get(0).typeArgs()); edit.cellTypeArgs(edit.scopeTypeArgs().get(0).typeArgs());
} }
public Result writeScope(Reference<RowBuffer> b, Reference<RowCursor> edit, public Result writeScope(
TypeArgumentList typeArgs, boolean hasValue, Out<RowCursor> value) { RowBuffer buffer,
return writeScope(b, edit, typeArgs, hasValue, value, UpdateOptions.Upsert); 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: public Result writeScope(
//ORIGINAL LINE: public Result WriteScope(ref RowBuffer b, ref RowCursor edit, TypeArgumentList typeArgs, bool @Nonnull final RowBuffer buffer,
// hasValue, out RowCursor value, UpdateOptions options = UpdateOptions.Upsert) @Nonnull final RowCursor edit,
public Result writeScope(Reference<RowBuffer> b, Reference<RowCursor> edit, @Nonnull final TypeArgumentList typeArgs,
TypeArgumentList typeArgs, boolean hasValue, Out<RowCursor> value, boolean hasValue,
UpdateOptions options) { @Nonnull final UpdateOptions options,
Result result = LayoutType.prepareSparseWrite(b, edit, new TypeArgument(this, typeArgs.clone()), 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) { if (result != Result.SUCCESS) {
value.setAndGet(null); value.set(null);
return result; return result;
} }
b.get().writeNullable(edit, this, typeArgs.clone(), options, hasValue); buffer.writeNullable(edit, this, typeArgs, options, hasValue);
return Result.SUCCESS; return Result.SUCCESS;
} }
@Override @Override
public Result writeScope(RowBuffer buffer, RowCursor edit, @Nonnull
TypeArgumentList typeArgs, Out<RowCursor> value) { public Result writeScope(
return writeScope(buffer, edit, typeArgs, UpdateOptions.Upsert, value); @Nonnull final RowBuffer buffer,
} @Nonnull final RowCursor edit,
@Nonnull final TypeArgumentList typeArgs,
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above: @Nonnull final Out<RowCursor> value) {
//ORIGINAL LINE: public override Result WriteScope(ref RowBuffer b, ref RowCursor edit, TypeArgumentList return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value);
// 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);
} }
@Override @Override
public int writeTypeArgument(Reference<RowBuffer> row, int offset, TypeArgumentList value) { @Nonnull
checkState(value.count() == 1); public Result writeScope(
row.get().writeSparseTypeCode(offset, this.LayoutCode); @Nonnull final RowBuffer buffer,
int lenInBytes = (com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE); @Nonnull final RowCursor edit,
lenInBytes += value.get(0).type().writeTypeArgument(row, offset + lenInBytes, @Nonnull final TypeArgumentList typeArgs,
value.get(0).typeArgs().clone()); @Nonnull final UpdateOptions options,
return lenInBytes; @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.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor; import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull;
public final class LayoutObject extends LayoutPropertyScope { public final class LayoutObject extends LayoutPropertyScope {
private TypeArgument TypeArg = new TypeArgument();
private TypeArgument typeArg;
public LayoutObject(boolean immutable) { public LayoutObject(boolean immutable) {
super(immutable ? com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.IMMUTABLE_OBJECT_SCOPE : super(immutable ? LayoutCode.IMMUTABLE_OBJECT_SCOPE : LayoutCode.OBJECT_SCOPE, immutable);
com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.OBJECT_SCOPE, immutable); this.typeArg = new TypeArgument(this);
this.TypeArg = new TypeArgument(this);
} }
@Override
@Nonnull
public String name() { public String name() {
return this.Immutable ? "im_object" : "object"; return this.isImmutable() ? "im_object" : "object";
} }
public TypeArgument typeArg() { public TypeArgument typeArg() {
return TypeArg; return this.typeArg;
} }
@Override @Override
public Result writeScope(RowBuffer buffer, RowCursor edit, @Nonnull
TypeArgumentList typeArgs, Out<RowCursor> value) { 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 @Override
public Result writeScope(RowBuffer buffer, RowCursor edit, @Nonnull
TypeArgumentList typeArgs, UpdateOptions options, Out<RowCursor> value) { public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, UpdateOptions options, Out<RowCursor> value) {
Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg().clone(), options);
Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options);
if (result != Result.SUCCESS) { if (result != Result.SUCCESS) {
value.setAndGet(null); value.setAndGet(null);
return result; return result;
} }
buffer.get().WriteSparseObject(edit, this, options, value.clone()); value.set(buffer.writeSparseObject(edit, this, options));
return Result.SUCCESS; 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.Namespace;
import com.azure.data.cosmos.serialization.hybridrow.schemas.Schema; 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.Preconditions.checkState;
import static com.google.common.base.Strings.lenientFormat; 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. * All members of this class are multi-thread safe.
*/ */
public final class LayoutResolverNamespace extends LayoutResolver { 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); this(schemaNamespace, null);
} }
public LayoutResolverNamespace(Namespace schemaNamespace, LayoutResolver parent) { public LayoutResolverNamespace(@Nonnull final Namespace schemaNamespace, @Nullable final LayoutResolver parent) {
this.schemaNamespace = schemaNamespace; this.schemaNamespace = schemaNamespace;
this.parent = parent; 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; return this.schemaNamespace;
} }
@Override @Override
public Layout resolve(SchemaId schemaId) { 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()) { Layout layout = this.layoutCache.computeIfAbsent(schemaId, id -> {
if (SchemaId.opEquals(s.schemaId().clone(), for (Schema schema : this.namespace().schemas()) {
schemaId.clone())) { if (schema.schemaId().equals(id)) {
layout = s.compile(this.schemaNamespace); return schema.compile(this.schemaNamespace);
layout = this.layoutCache.putIfAbsent(schemaId.value(), layout); }
return layout;
} }
} return this.parent == null ? null : this.parent.resolve(schemaId);
});
layout = this.parent == null ? null : this.parent.resolve(schemaId.clone()); checkState(layout != null, "failed to resolve schema %s", schemaId);
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()));
return null; return null;
} }
} }

View File

@@ -132,10 +132,10 @@ public abstract class LayoutScope extends LayoutType {
return Result.SUCCESS; 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> pathLenInBytes = new Out<>();
Out<Integer> pathOffset = 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.pathOffset(pathOffset.get());
edit.valueOffset(edit.valueOffset() + pathLenInBytes.get()); edit.valueOffset(edit.valueOffset() + pathLenInBytes.get());
} }
@@ -163,7 +163,7 @@ public abstract class LayoutScope extends LayoutType {
RowCursor scope, RowCursor scope,
TypeArgumentList typeArgs, TypeArgumentList typeArgs,
TContext context, WriterFunc<TContext> func) { 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 @Nonnull

View File

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

View File

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

View File

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

View File

@@ -4,74 +4,96 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts; package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out; 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.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor; 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 final class LayoutTypedArray extends LayoutIndexedScope {
public LayoutTypedArray(boolean immutable) { public LayoutTypedArray(boolean immutable) {
super(immutable ? com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.IMMUTABLE_TYPED_ARRAY_SCOPE : 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); com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.TYPED_ARRAY_SCOPE, immutable, true, false, false, true);
} }
public String name() { @Override
return this.Immutable ? "im_array_t" : "array_t"; public int countTypeArgument(@Nonnull TypeArgumentList value) {
} checkNotNull(value, "expected non-null value");
public int countTypeArgument(TypeArgumentList value) {
checkState(value.count() == 1); 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 @Override
public boolean HasImplicitTypeCode(Reference<RowCursor> edit) { public boolean hasImplicitTypeCode(RowCursor edit) {
checkState(edit.get().index() >= 0); checkState(edit.index() >= 0);
checkState(edit.get().scopeTypeArgs().count() == 1); checkState(edit.scopeTypeArgs().count() == 1);
return !LayoutCodeTraits.alwaysRequiresTypeCode(edit.get().scopeTypeArgs().get(0).type().LayoutCode); return !LayoutCodeTraits.alwaysRequiresTypeCode(edit.scopeTypeArgs().get(0).type().layoutCode());
} }
@Override @Override
public TypeArgumentList readTypeArgumentList(Reference<RowBuffer> row, int offset, @Nonnull
Out<Integer> lenInBytes) { public String name() {
return new TypeArgumentList(new TypeArgument[] { LayoutType.readTypeArgument(row, offset, lenInBytes) }); return this.isImmutable() ? "im_array_t" : "array_t";
} }
@Override @Override
public void setImplicitTypeCode(RowCursor edit) { @Nonnull
edit.get().cellType = edit.get().scopeTypeArgs().get(0).type(); public TypeArgumentList readTypeArgumentList(RowBuffer buffer, int offset, Out<Integer> lenInBytes) {
edit.get().cellTypeArgs = edit.get().scopeTypeArgs().get(0).typeArgs().clone(); return new TypeArgumentList(LayoutType.readTypeArgument(buffer, offset, lenInBytes));
} }
@Override @Override
public Result writeScope(RowBuffer buffer, RowCursor edit, public void setImplicitTypeCode(@Nonnull final RowCursor edit) {
TypeArgumentList typeArgs, Out<RowCursor> value) { edit.cellType(edit.scopeTypeArgs().get(0).type());
return writeScope(buffer, edit, typeArgs, UpdateOptions.Upsert, value); 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 @Override
public Result writeScope(RowBuffer buffer, RowCursor edit, @Nonnull
TypeArgumentList typeArgs, UpdateOptions options, Out<RowCursor> value) { public Result writeScope(
Result result = LayoutType.prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs.clone()), options); @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) { if (result != Result.SUCCESS) {
value.setAndGet(null); value.set(null);
return result; return result;
} }
buffer.get().WriteTypedArray(edit, this, typeArgs.clone(), options, value.clone()); value.set(buffer.writeTypedArray(edit, this, typeArgs, options));
return Result.SUCCESS; return Result.SUCCESS;
} }
@Override @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); checkState(value.count() == 1);
row.get().writeSparseTypeCode(offset, this.LayoutCode);
int lenInBytes = (com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE); TypeArgument typeArg = value.get(0);
lenInBytes += value.get(0).type().writeTypeArgument(row, offset + lenInBytes, buffer.writeSparseTypeCode(offset, this.layoutCode());
value.get(0).typeArgs().clone());
return lenInBytes; 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; package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out; 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.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor; 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 final class LayoutTypedMap extends LayoutUniqueScope {
public LayoutTypedMap(boolean immutable) { public LayoutTypedMap(boolean immutable) {
super(immutable ? com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.IMMUTABLE_TYPED_MAP_SCOPE : 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) true, isTypedScope():true)
} }
public String name() { @Override
return this.Immutable ? "im_map_t" : "map_t"; public int countTypeArgument(@Nonnull TypeArgumentList value) {
} checkNotNull(value, "expected non-null value");
public int countTypeArgument(TypeArgumentList value) {
checkState(value.count() == 2); checkState(value.count() == 2);
int lenInBytes = (com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE); return value.stream()
for (TypeArgument arg : value) { .map(arg -> arg.type().countTypeArgument(arg.typeArgs()))
lenInBytes += arg.type().CountTypeArgument(arg.typeArgs().clone()); .reduce(LayoutCode.BYTES, Integer::sum);
}
return lenInBytes;
} }
@Nonnull
@Override @Override
public TypeArgument fieldType(RowCursor scope) { public TypeArgument fieldType(RowCursor scope) {
return new TypeArgument(scope.get().scopeType().Immutable ? ImmutableTypedTuple : return new TypeArgument(
TypedTuple, scope.get().scopeTypeArgs().clone()); scope.scopeType().isImmutable() ? LayoutTypes.IMMUTABLE_TYPED_TUPLE : LayoutTypes.TYPED_TUPLE,
scope.scopeTypeArgs());
} }
@Override @Override
public boolean HasImplicitTypeCode(Reference<RowCursor> edit) { public boolean hasImplicitTypeCode(RowCursor edit) {
return true; return true;
} }
@Nonnull
public String name() {
return this.isImmutable() ? "im_map_t" : "map_t";
}
@Override @Override
public TypeArgumentList readTypeArgumentList(Reference<RowBuffer> row, int offset, public TypeArgumentList readTypeArgumentList(RowBuffer row, int offset,
Out<Integer> lenInBytes) { Out<Integer> lenInBytes) {
lenInBytes.setAndGet(0); lenInBytes.setAndGet(0);
TypeArgument[] retval = new TypeArgument[2]; TypeArgument[] retval = new TypeArgument[2];
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
int itemLenInBytes; int itemLenInBytes;
Out<Integer> tempOut_itemLenInBytes = new Out<Integer>(); Out<Integer> tempOut_itemLenInBytes = new Out<Integer>();
retval[i] = readTypeArgument(row, offset + lenInBytes.get(), tempOut_itemLenInBytes); retval[i] = readTypeArgument(row, offset + lenInBytes, tempOut_itemLenInBytes);
itemLenInBytes = tempOut_itemLenInBytes.get(); itemLenInBytes = tempOut_itemLenInBytes;
lenInBytes.setAndGet(lenInBytes.get() + itemLenInBytes); lenInBytes.setAndGet(lenInBytes + itemLenInBytes);
} }
return new TypeArgumentList(retval); return new TypeArgumentList(retval);
@@ -59,40 +65,39 @@ public final class LayoutTypedMap extends LayoutUniqueScope {
@Override @Override
public void setImplicitTypeCode(RowCursor edit) { public void setImplicitTypeCode(RowCursor edit) {
edit.get().cellType = edit.get().scopeType().Immutable ? ImmutableTypedTuple : edit.cellType(edit.scopeType().isImmutable() ? LayoutTypes.IMMUTABLE_TYPED_TUPLE : LayoutTypes.TYPED_TUPLE);
TypedTuple; edit.cellTypeArgs(edit.scopeTypeArgs());
edit.get().cellTypeArgs = edit.get().scopeTypeArgs().clone();
} }
@Override @Override
public Result writeScope(RowBuffer buffer, RowCursor edit, @Nonnull
TypeArgumentList typeArgs, Out<RowCursor> value) { 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 @Override
public Result writeScope(RowBuffer buffer, RowCursor edit, @Nonnull
TypeArgumentList typeArgs, UpdateOptions options, Out<RowCursor> value) { public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, UpdateOptions options,
Result result = prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs.clone()), options); Out<RowCursor> value) {
Result result = prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs), options);
if (result != Result.SUCCESS) { if (result != Result.SUCCESS) {
value.setAndGet(null); value.setAndGet(null);
return result; return result;
} }
buffer.get().WriteTypedMap(edit, this, typeArgs.clone(), options, value.clone()); value.set(buffer.writeTypedMap(edit, this, typeArgs, options));
return Result.SUCCESS; return Result.SUCCESS;
} }
@Override @Override
public int writeTypeArgument(Reference<RowBuffer> row, int offset, TypeArgumentList value) { public int writeTypeArgument(RowBuffer buffer, int offset, TypeArgumentList value) {
checkState(value.count() == 2); checkState(value.count() == 2);
row.get().writeSparseTypeCode(offset, this.LayoutCode); buffer.writeSparseTypeCode(offset, this.layoutCode());
int lenInBytes = (com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE); int lenInBytes = LayoutCode.BYTES;
for (TypeArgument arg : value) { 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; return lenInBytes;

View File

@@ -4,81 +4,92 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts; package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out; 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.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor; 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.IMMUTABLE_TYPED_SET_SCOPE;
import static com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.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 final class LayoutTypedSet extends LayoutUniqueScope {
public LayoutTypedSet(boolean immutable) { public LayoutTypedSet(boolean immutable) {
super(immutable ? IMMUTABLE_TYPED_SET_SCOPE : TYPED_SET_SCOPE, immutable, true, true); super(immutable ? IMMUTABLE_TYPED_SET_SCOPE : TYPED_SET_SCOPE, immutable, true, true);
} }
public String name() { @Override
return this.Immutable ? "im_set_t" : "set_t"; public int countTypeArgument(@Nonnull TypeArgumentList value) {
} checkNotNull(value, "expected non-null value");
public int countTypeArgument(TypeArgumentList value) {
checkState(value.count() == 1); 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 @Override
public TypeArgument fieldType(RowCursor scope) { public TypeArgument fieldType(RowCursor scope) {
return scope.get().scopeTypeArgs().get(0).clone(); return scope.scopeTypeArgs().get(0);
} }
@Override @Override
public boolean HasImplicitTypeCode(Reference<RowCursor> edit) { public boolean hasImplicitTypeCode(RowCursor edit) {
checkState(edit.get().index() >= 0); checkState(edit.index() >= 0);
checkState(edit.get().scopeTypeArgs().count() == 1); checkState(edit.scopeTypeArgs().count() == 1);
return !LayoutCodeTraits.alwaysRequiresTypeCode(edit.get().scopeTypeArgs().get(0).type().LayoutCode); return !LayoutCodeTraits.alwaysRequiresTypeCode(edit.scopeTypeArgs().get(0).type().layoutCode());
}
@Nonnull
public String name() {
return this.isImmutable() ? "im_set_t" : "set_t";
} }
@Override @Override
public TypeArgumentList readTypeArgumentList(Reference<RowBuffer> row, int offset, @Nonnull
Out<Integer> lenInBytes) { public TypeArgumentList readTypeArgumentList(RowBuffer buffer, int offset, Out<Integer> lenInBytes) {
return new TypeArgumentList(new TypeArgument[] { readTypeArgument(row, offset, lenInBytes) }); return new TypeArgumentList(readTypeArgument(buffer, offset, lenInBytes));
} }
@Override @Override
public void setImplicitTypeCode(RowCursor edit) { public void setImplicitTypeCode(RowCursor edit) {
edit.get().cellType = edit.get().scopeTypeArgs().get(0).type(); edit.cellType(edit.scopeTypeArgs().get(0).type());
edit.get().cellTypeArgs = edit.get().scopeTypeArgs().get(0).typeArgs().clone(); edit.cellTypeArgs(edit.scopeTypeArgs().get(0).typeArgs());
} }
@Override @Override
@Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, public Result writeScope(RowBuffer buffer, RowCursor edit,
TypeArgumentList typeArgs, Out<RowCursor> value) { 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: //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 //ORIGINAL LINE: public override Result WriteScope(ref RowBuffer b, ref RowCursor edit, TypeArgumentList
// typeArgs, out RowCursor value, UpdateOptions options = UpdateOptions.Upsert) // typeArgs, out RowCursor value, UpdateOptions options = UpdateOptions.Upsert)
@Override @Override
@Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, public Result writeScope(RowBuffer buffer, RowCursor edit,
TypeArgumentList typeArgs, UpdateOptions options, Out<RowCursor> value) { 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) { if (result != Result.SUCCESS) {
value.setAndGet(null); value.setAndGet(null);
return result; return result;
} }
buffer.get().WriteTypedSet(edit, this, typeArgs.clone(), options, value.clone()); buffer.writeTypedSet(edit, this, typeArgs, options, value);
return Result.SUCCESS; return Result.SUCCESS;
} }
@Override @Override
public int writeTypeArgument(Reference<RowBuffer> row, int offset, TypeArgumentList value) { public int writeTypeArgument(RowBuffer buffer, int offset, TypeArgumentList value) {
checkArgument(value.count() == 1); checkArgument(value.count() == 1);
row.get().writeSparseTypeCode(offset, this.LayoutCode); buffer.writeSparseTypeCode(offset, this.layoutCode());
int lenInBytes = (com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE); int lenInBytes = LayoutCode.BYTES;
lenInBytes += value.get(0).type().writeTypeArgument(row, offset + lenInBytes, lenInBytes += value.get(0).type().writeTypeArgument(buffer, offset + lenInBytes,
value.get(0).typeArgs().clone()); value.get(0).typeArgs());
return lenInBytes; return lenInBytes;
} }
} }

View File

@@ -4,95 +4,100 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts; package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out; 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.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor; 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.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
public final class LayoutTypedTuple extends LayoutIndexedScope { public final class LayoutTypedTuple extends LayoutIndexedScope {
public LayoutTypedTuple(boolean immutable) { public LayoutTypedTuple(boolean immutable) {
super(immutable ? com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.IMMUTABLE_TYPED_TUPLE_SCOPE : super(
com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.TYPED_TUPLE_SCOPE, immutable, true, true, false, true); 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() { public String name() {
return this.Immutable ? "im_tuple_t" : "tuple_t"; return this.isImmutable() ? "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;
} }
@Override @Override
public boolean HasImplicitTypeCode(Reference<RowCursor> edit) { public TypeArgumentList readTypeArgumentList(RowBuffer row, int offset, Out<Integer> lenInBytes) {
checkArgument(edit.get().index() >= 0);
checkArgument(edit.get().scopeTypeArgs().count() > edit.get().index()); int numTypeArgs = row.read7BitEncodedUInt(offset, lenInBytes);
return !LayoutCodeTraits.alwaysRequiresTypeCode(edit.get().scopeTypeArgs().get(edit.get().index()).type().LayoutCode); 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++) { for (int i = 0; i < numTypeArgs; i++) {
int itemLenInBytes; int itemLenInBytes;
Out<Integer> tempOut_itemLenInBytes = new Out<Integer>(); Out<Integer> tempOut_itemLenInBytes = new Out<Integer>();
retval[i] = LayoutType.readTypeArgument(row, offset + lenInBytes.get(), tempOut_itemLenInBytes); typeArgs[i] = LayoutType.readTypeArgument(row, offset + lenInBytes, tempOut_itemLenInBytes);
itemLenInBytes = tempOut_itemLenInBytes.get(); itemLenInBytes = tempOut_itemLenInBytes;
lenInBytes.setAndGet(lenInBytes.get() + itemLenInBytes); lenInBytes.setAndGet(lenInBytes + itemLenInBytes);
} }
return new TypeArgumentList(retval); return new TypeArgumentList(typeArgs);
} }
@Override @Override
public void setImplicitTypeCode(RowCursor edit) { public void setImplicitTypeCode(RowCursor edit) {
edit.get().cellType = edit.get().scopeTypeArgs().get(edit.get().index()).type(); edit.cellType(edit.scopeTypeArgs().get(edit.index()).type());
edit.get().cellTypeArgs = edit.get().scopeTypeArgs().get(edit.get().index()).typeArgs().clone(); edit.cellTypeArgs(edit.scopeTypeArgs().get(edit.index()).typeArgs());
} }
@Override @Override
@Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, public Result writeScope(RowBuffer buffer, RowCursor edit,
TypeArgumentList typeArgs, Out<RowCursor> value) { 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 @Override
public Result writeScope(RowBuffer buffer, RowCursor edit, @Nonnull
TypeArgumentList typeArgs, UpdateOptions options, Out<RowCursor> value) { public Result writeScope(
Result result = LayoutType.prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs.clone()), options); 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) { if (result != Result.SUCCESS) {
value.setAndGet(null); value.setAndGet(null);
return result; return result;
} }
buffer.get().WriteTypedTuple(edit, this, typeArgs.clone(), options, value.clone()); value.set(buffer.writeTypedTuple(edit, this, typeArgs, options));
return Result.SUCCESS; return Result.SUCCESS;
} }
@Override @Override
public int writeTypeArgument(Reference<RowBuffer> row, int offset, TypeArgumentList value) { public int writeTypeArgument(RowBuffer buffer, int offset, TypeArgumentList value) {
row.get().writeSparseTypeCode(offset, this.LayoutCode); buffer.writeSparseTypeCode(offset, this.layoutCode());
int lenInBytes = (com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE); int lenInBytes = LayoutCode.BYTES;
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: lenInBytes += row.Write7BitEncodedUInt(offset + lenInBytes, (ulong)value.Count); //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) { 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; return lenInBytes;

View File

@@ -4,61 +4,68 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts; package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out; 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.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor; import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import com.azure.data.cosmos.serialization.hybridrow.SchemaId; 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 final class LayoutUDT extends LayoutPropertyScope {
public LayoutUDT(boolean immutable) { public LayoutUDT(boolean immutable) {
super(immutable ? com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.IMMUTABLE_SCHEMA : super(immutable ? LayoutCode.IMMUTABLE_SCHEMA : LayoutCode.SCHEMA, immutable);
com.azure.data.cosmos.serialization.hybridrow.layouts.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() { public String name() {
return this.Immutable ? "im_udt" : "udt"; return this.isImmutable() ? "im_udt" : "udt";
}
public int countTypeArgument(TypeArgumentList value) {
return (com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE) + SchemaId.BYTES;
} }
@Override @Override
public TypeArgumentList readTypeArgumentList(Reference<RowBuffer> row, int offset, @Nonnull
Out<Integer> lenInBytes) { public TypeArgumentList readTypeArgumentList(RowBuffer row, int offset, Out<Integer> lenInBytes) {
SchemaId schemaId = row.get().readSchemaId(offset).clone(); SchemaId schemaId = row.readSchemaId(offset);
lenInBytes.setAndGet(SchemaId.BYTES); lenInBytes.set(SchemaId.BYTES);
return new TypeArgumentList(schemaId.clone()); return new TypeArgumentList(schemaId);
} }
@Override @Override
public Result writeScope(RowBuffer buffer, RowCursor edit, @Nonnull
TypeArgumentList typeArgs, Out<RowCursor> value) { 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 @Override
public Result writeScope(RowBuffer buffer, RowCursor edit, @Nonnull
TypeArgumentList typeArgs, UpdateOptions options, Out<RowCursor> value) { public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, UpdateOptions options,
Layout udt = buffer.get().resolver().resolve(typeArgs.schemaId().clone()); Out<RowCursor> value) {
Result result = prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs.clone()), options);
Layout udt = buffer.resolver().resolve(typeArgs.schemaId());
Result result = prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs), options);
if (result != Result.SUCCESS) { if (result != Result.SUCCESS) {
value.setAndGet(null); value.set(null);
return result; return result;
} }
buffer.get().WriteSparseUDT(edit, this, udt, options, value.clone()); value.set(buffer.writeSparseUDT(edit, this, udt, options));
return Result.SUCCESS; return Result.SUCCESS;
} }
@Override @Override
public int writeTypeArgument(Reference<RowBuffer> row, int offset, TypeArgumentList value) { public int writeTypeArgument(RowBuffer buffer, int offset, TypeArgumentList value) {
row.get().writeSparseTypeCode(offset, this.LayoutCode); buffer.writeSparseTypeCode(offset, this.layoutCode());
row.get().writeSchemaId(offset + (com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE), value.schemaId().clone()); buffer.writeSchemaId(offset + LayoutCode.BYTES, value.schemaId());
return (com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE) + SchemaId.BYTES; return LayoutCode.BYTES + SchemaId.BYTES;
} }
} }

View File

@@ -4,93 +4,91 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts; package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out; 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.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor; 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.checkArgument;
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: public final class LayoutUInt16 extends LayoutType<Integer> {
//ORIGINAL LINE: public sealed class LayoutUInt16 : LayoutType<ushort>
public final class LayoutUInt16 extends LayoutType<Short> {
public LayoutUInt16() { 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() { public boolean isFixed() {
return true; return true;
} }
@Nonnull
public String name() { public String name() {
return "uint16"; 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 @Override
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, @Nonnull
Out<Short> value) { 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())) { checkArgument(scope.scopeType() instanceof LayoutUDT);
value.setAndGet(0);
if (!buffer.readBit(scope.start(), column.nullBit())) {
value.set(0);
return Result.NOT_FOUND; 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; 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 @Override
public Result readSparse(RowBuffer buffer, RowCursor edit, @Nonnull
Out<Short> value) { public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Integer> value) {
Result result = prepareSparseRead(buffer, edit, this.LayoutCode);
Result result = prepareSparseRead(buffer, edit, this.layoutCode());
if (result != Result.SUCCESS) { if (result != Result.SUCCESS) {
value.setAndGet(0); value.set(0);
return result; return result;
} }
value.setAndGet(buffer.get().ReadSparseUInt16(edit)); value.set(buffer.readSparseUInt16(edit));
return Result.SUCCESS; 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 @Override
public Result WriteFixed(Reference<RowBuffer> b, Reference<RowCursor> scope, LayoutColumn col, @Nonnull
short value) { public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Integer value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT);
if (scope.get().immutable()) { checkArgument(scope.scopeType() instanceof LayoutUDT);
if (scope.immutable()) {
return Result.INSUFFICIENT_PERMISSIONS; return Result.INSUFFICIENT_PERMISSIONS;
} }
b.get().writeUInt16(scope.get().start() + col.getOffset(), value); buffer.writeUInt16(scope.start() + column.offset(), value.shortValue());
b.get().setBit(scope.get().start(), col.getNullBit().clone()); buffer.setBit(scope.start(), column.nullBit());
return Result.SUCCESS; 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 @Override
public Result WriteSparse(Reference<RowBuffer> b, Reference<RowCursor> edit, short value, @Nonnull
UpdateOptions options) { public Result writeSparse(RowBuffer buffer, RowCursor edit, Integer value, UpdateOptions options) {
Result result = prepareSparseWrite(b, edit, this.typeArg().clone(), options);
Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options);
if (result != Result.SUCCESS) { if (result != Result.SUCCESS) {
return result; return result;
} }
b.get().writeSparseUInt16(edit, value, options); buffer.writeSparseUInt16(edit, value.shortValue(), options);
return Result.SUCCESS; return Result.SUCCESS;
} }
@Override @Override
public Result WriteSparse(Reference<RowBuffer> b, Reference<RowCursor> edit, short value) { @Nonnull
return 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

@@ -4,93 +4,88 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts; package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out; 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.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor; 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.checkArgument;
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: public final class LayoutUInt32 extends LayoutType<Long> {
//ORIGINAL LINE: public sealed class LayoutUInt32 : LayoutType<uint>
public final class LayoutUInt32 extends LayoutType<Integer> {
public LayoutUInt32() { 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() { public boolean isFixed() {
return true; return true;
} }
@Nonnull
public String name() { public String name() {
return "uint32"; 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 @Override
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, @Nonnull
Out<Integer> value) { 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())) { checkArgument(scope.scopeType() instanceof LayoutUDT);
value.setAndGet(0);
if (!buffer.readBit(scope.start(), column.nullBit())) {
value.set(0L);
return Result.NOT_FOUND; 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; 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 @Override
public Result readSparse(RowBuffer buffer, RowCursor edit, @Nonnull
Out<Integer> value) { 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) { if (result != Result.SUCCESS) {
value.setAndGet(0); value.set(0L);
return result; return result;
} }
value.setAndGet(buffer.get().ReadSparseUInt32(edit)); value.set(buffer.readSparseUInt32(edit));
return Result.SUCCESS; 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 @Override
public Result WriteFixed(Reference<RowBuffer> b, Reference<RowCursor> scope, LayoutColumn col, @Nonnull
int value) { public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Long value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT);
if (scope.get().immutable()) { checkArgument(scope.scopeType() instanceof LayoutUDT);
if (scope.immutable()) {
return Result.INSUFFICIENT_PERMISSIONS; return Result.INSUFFICIENT_PERMISSIONS;
} }
b.get().writeUInt32(scope.get().start() + col.getOffset(), value); buffer.writeUInt32(scope.start() + column.offset(), value.intValue());
b.get().setBit(scope.get().start(), col.getNullBit().clone()); buffer.setBit(scope.start(), column.nullBit());
return Result.SUCCESS; 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 @Override
public Result WriteSparse(Reference<RowBuffer> b, Reference<RowCursor> edit, int value, @Nonnull
UpdateOptions options) { public Result writeSparse(RowBuffer buffer, RowCursor edit, Long value, UpdateOptions options) {
Result result = prepareSparseWrite(b, edit, this.typeArg().clone(), options); Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options);
if (result != Result.SUCCESS) { if (result != Result.SUCCESS) {
return result; return result;
} }
buffer.writeSparseUInt32(edit, value.intValue(), options);
b.get().writeSparseUInt32(edit, value, options);
return Result.SUCCESS; return Result.SUCCESS;
} }
@Override @Override
public Result WriteSparse(Reference<RowBuffer> b, Reference<RowCursor> edit, int value) { @Nonnull
return 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

@@ -4,93 +4,92 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts; package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out; 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.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor; 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.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 final class LayoutUInt64 extends LayoutType<Long> {
public LayoutUInt64() { 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() { public boolean isFixed() {
return true; return true;
} }
@Nonnull
public String name() { public String name() {
return "uint64"; 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 @Override
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, @Nonnull
Out<Long> value) { 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())) { checkArgument(scope.scopeType() instanceof LayoutUDT);
value.setAndGet(0);
if (!buffer.readBit(scope.start(), column.nullBit())) {
value.set(0L);
return Result.NOT_FOUND; 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; 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 @Override
public Result readSparse(RowBuffer buffer, RowCursor edit, @Nonnull
Out<Long> value) { 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) { if (result != Result.SUCCESS) {
value.setAndGet(0); value.set(0L);
return result; return result;
} }
value.setAndGet(buffer.get().ReadSparseUInt64(edit)); value.set(buffer.readSparseUInt64(edit));
return Result.SUCCESS; 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 @Override
public Result WriteFixed(Reference<RowBuffer> b, Reference<RowCursor> scope, LayoutColumn col, @Nonnull
long value) { public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Long value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT);
if (scope.get().immutable()) { checkArgument(scope.scopeType() instanceof LayoutUDT);
if (scope.immutable()) {
return Result.INSUFFICIENT_PERMISSIONS; return Result.INSUFFICIENT_PERMISSIONS;
} }
b.get().writeUInt64(scope.get().start() + col.getOffset(), value); buffer.writeUInt64(scope.start() + column.offset(), value);
b.get().setBit(scope.get().start(), col.getNullBit().clone()); buffer.setBit(scope.start(), column.nullBit());
return Result.SUCCESS; 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 @Override
public Result WriteSparse(Reference<RowBuffer> b, Reference<RowCursor> edit, long value, @Nonnull
UpdateOptions options) { public Result writeSparse(RowBuffer buffer, RowCursor edit, Long value, UpdateOptions options) {
Result result = prepareSparseWrite(b, edit, this.typeArg().clone(), options);
Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options);
if (result != Result.SUCCESS) { if (result != Result.SUCCESS) {
return result; return result;
} }
b.get().writeSparseUInt64(edit, value, options); buffer.writeSparseUInt64(edit, value, options);
return Result.SUCCESS; return Result.SUCCESS;
} }
@Override @Override
public Result WriteSparse(Reference<RowBuffer> b, Reference<RowCursor> edit, long value) { @Nonnull
return 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

@@ -4,93 +4,92 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts; package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out; 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.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor; 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.checkArgument;
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: public final class LayoutUInt8 extends LayoutType<Short> {
//ORIGINAL LINE: public sealed class LayoutUInt8 : LayoutType<byte>
public final class LayoutUInt8 extends LayoutType<Byte> {
public LayoutUInt8() { public LayoutUInt8() {
super(com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.UINT_8, 1); super(LayoutCode.UINT_8, 1);
} }
public boolean isFixed() { public boolean isFixed() {
return true; return true;
} }
@Nonnull
public String name() { public String name() {
return "uint8"; 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 @Override
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, @Nonnull
Out<Byte> value) { 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())) { checkArgument(scope.scopeType() instanceof LayoutUDT);
value.setAndGet(0);
if (!buffer.readBit(scope.start(), column.nullBit())) {
value.set((short) 0);
return Result.NOT_FOUND; 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; 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 @Override
public Result readSparse(RowBuffer buffer, RowCursor edit, @Nonnull
Out<Byte> value) { public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Short> value) {
Result result = prepareSparseRead(buffer, edit, this.LayoutCode);
Result result = prepareSparseRead(buffer, edit, this.layoutCode());
if (result != Result.SUCCESS) { if (result != Result.SUCCESS) {
value.setAndGet(0); value.set((short) 0);
return result; return result;
} }
value.setAndGet(buffer.get().ReadSparseUInt8(edit)); value.set(buffer.readSparseUInt8(edit));
return Result.SUCCESS; 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 @Override
public Result WriteFixed(Reference<RowBuffer> b, Reference<RowCursor> scope, LayoutColumn col, @Nonnull
byte value) { public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Short value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT);
if (scope.get().immutable()) { checkArgument(scope.scopeType() instanceof LayoutUDT);
if (scope.immutable()) {
return Result.INSUFFICIENT_PERMISSIONS; return Result.INSUFFICIENT_PERMISSIONS;
} }
b.get().writeUInt8(scope.get().start() + col.getOffset(), value); buffer.writeUInt8(scope.start() + column.offset(), value.byteValue());
b.get().setBit(scope.get().start(), col.getNullBit().clone()); buffer.setBit(scope.start(), column.nullBit());
return Result.SUCCESS; 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 @Override
public Result WriteSparse(Reference<RowBuffer> b, Reference<RowCursor> edit, byte value, @Nonnull
UpdateOptions options) { public Result writeSparse(RowBuffer buffer, RowCursor edit, Short value, UpdateOptions options) {
Result result = prepareSparseWrite(b, edit, this.typeArg().clone(), options);
Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options);
if (result != Result.SUCCESS) { if (result != Result.SUCCESS) {
return result; return result;
} }
b.get().writeSparseUInt8(edit, value, options); buffer.writeSparseUInt8(edit, value.byteValue(), options);
return Result.SUCCESS; return Result.SUCCESS;
} }
@Override @Override
public Result WriteSparse(Reference<RowBuffer> b, Reference<RowCursor> edit, byte value) { @Nonnull
return WriteSparse(b, edit, value, UpdateOptions.Upsert); 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); super(code, immutable, isSizedScope, false, true, isTypedScope);
} }
@Nonnull
public abstract TypeArgument fieldType(RowCursor scope); 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 * @return Success a matching field exists in the unique index, NotFound if no match is found, the error code
* otherwise. * otherwise.
*/ */
@Nonnull
public final Result find(RowBuffer buffer, RowCursor scope, RowCursor patternScope, Out<RowCursor> value) { public final Result find(RowBuffer buffer, RowCursor scope, RowCursor patternScope, Out<RowCursor> value) {
Result result = LayoutType.prepareSparseMove(buffer, scope, this, this.fieldType(scope), patternScope, Result result = LayoutType.prepareSparseMove(buffer, scope, this, this.fieldType(scope), patternScope,
UpdateOptions.Update, value); UpdateOptions.UPDATE, value);
if (result != Result.SUCCESS) { if (result != Result.SUCCESS) {
return result; return result;
@@ -60,6 +62,7 @@ public abstract class LayoutUniqueScope extends LayoutIndexedScope {
* @param options The move options. * @param options The move options.
* @return Success if the field is permitted within the unique index, the error code otherwise. * @return Success if the field is permitted within the unique index, the error code otherwise.
*/ */
@Nonnull
public final Result moveField( public final Result moveField(
RowBuffer buffer, RowCursor destinationScope, RowCursor sourceEdit, UpdateOptions options) { RowBuffer buffer, RowCursor destinationScope, RowCursor sourceEdit, UpdateOptions options) {
@@ -94,8 +97,9 @@ public abstract class LayoutUniqueScope extends LayoutIndexedScope {
* <para /> * <para />
* The source field is delete whether the move succeeds or fails. * The source field is delete whether the move succeeds or fails.
*/ */
@Nonnull
public final Result moveField(RowBuffer buffer, RowCursor destinationScope, RowCursor sourceEdit) { 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 @Override
@@ -146,6 +150,6 @@ public abstract class LayoutUniqueScope extends LayoutIndexedScope {
@Nonnull @Nonnull
public <TContext> Result writeScope( public <TContext> Result writeScope(
RowBuffer buffer, RowCursor scope, TypeArgumentList typeArgs, TContext context, WriterFunc<TContext> func) { 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.RowCursor;
import com.azure.data.cosmos.serialization.hybridrow.UnixDateTime; import com.azure.data.cosmos.serialization.hybridrow.UnixDateTime;
import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument; 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() { public LayoutUnixDateTime() {
super(com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.UNIX_DATE_TIME, super(LayoutCode.UNIX_DATE_TIME, UnixDateTime.BYTES);
com.azure.data.cosmos.serialization.hybridrow.UnixDateTime.BYTES);
} }
public boolean isFixed() { public boolean isFixed() {
return true; return true;
} }
@Nonnull
public String name() { public String name() {
return "unixdatetime"; return "unixdatetime";
} }
@Override @Override
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, @Nonnull
Out<UnixDateTime> value) { 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())) { checkArgument(scope.scopeType() instanceof LayoutUDT);
value.setAndGet(null);
if (!buffer.readBit(scope.start(), column.nullBit())) {
value.set(null);
return Result.NOT_FOUND; 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; return Result.SUCCESS;
} }
@Override @Override
public Result readSparse(RowBuffer buffer, RowCursor edit, @Nonnull
Out<UnixDateTime> value) { public Result readSparse(RowBuffer buffer, RowCursor edit, Out<UnixDateTime> value) {
Result result = prepareSparseRead(buffer, edit, this.LayoutCode); Result result = prepareSparseRead(buffer, edit, this.layoutCode());
if (result != Result.SUCCESS) { if (result != Result.SUCCESS) {
value.setAndGet(null); value.set(null);
return result; return result;
} }
value.setAndGet(buffer.get().ReadSparseUnixDateTime(edit).clone()); value.set(buffer.readSparseUnixDateTime(edit));
return Result.SUCCESS; return Result.SUCCESS;
} }
@Override @Override
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, @Nonnull
UnixDateTime value) { public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, UnixDateTime value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT);
if (scope.get().immutable()) { checkArgument(scope.scopeType() instanceof LayoutUDT);
if (scope.immutable()) {
return Result.INSUFFICIENT_PERMISSIONS; return Result.INSUFFICIENT_PERMISSIONS;
} }
buffer.get().WriteUnixDateTime(scope.get().start() + column.getOffset(), value.clone()); buffer.writeUnixDateTime(scope.start() + column.offset(), value);
buffer.get().SetBit(scope.get().start(), column.getNullBit().clone()); buffer.setBit(scope.start(), column.nullBit());
return Result.SUCCESS; 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 @Override
public Result writeSparse(RowBuffer buffer, RowCursor edit, UnixDateTime value @Nonnull
, UpdateOptions options) { public Result writeSparse(RowBuffer buffer, RowCursor edit, UnixDateTime value, UpdateOptions options) {
Result result = prepareSparseWrite(buffer, edit, this.typeArg().clone(), options);
Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options);
if (result != Result.SUCCESS) { if (result != Result.SUCCESS) {
return result; return result;
} }
buffer.get().WriteSparseUnixDateTime(edit, value.clone(), options); buffer.writeSparseUnixDateTime(edit, value, options);
return Result.SUCCESS; return Result.SUCCESS;
} }
@Override @Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, UnixDateTime value) { 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; package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out; 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.core.Utf8String;
import com.azure.data.cosmos.serialization.hybridrow.Result; import com.azure.data.cosmos.serialization.hybridrow.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor; 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.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
public final class LayoutUtf8 extends LayoutType<String> implements ILayoutUtf8SpanWritable, ILayoutUtf8SpanReadable { public final class LayoutUtf8 extends LayoutType<String> implements ILayoutUtf8SpanWritable, ILayoutUtf8SpanReadable {
public LayoutUtf8() { public LayoutUtf8() {
super(com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.UTF_8, 0); super(LayoutCode.UTF_8, 0);
} }
public boolean isFixed() { public boolean isFixed() {
return false; return false;
} }
@Nonnull
public String name() { public String name() {
return "utf8"; return "utf8";
} }
@Override @Override
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<String> value) { @Nonnull
Utf8Span span; public Result readFixed(
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these @Nonnull final RowBuffer buffer,
// cannot be converted using the 'Out' helper class unless the method is within the code being modified: @Nonnull final RowCursor scope,
Result r = this.ReadFixed(buffer, scope, column, out span); @Nonnull final LayoutColumn column,
value.setAndGet((r == Result.SUCCESS) ? span.toString() :) @Nonnull final Out<String> value) {
default
return r; 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, @Override
Out<Utf8Span> value) { @Nonnull
checkArgument(scope.get().scopeType() instanceof LayoutUDT); public Result readFixedSpan(
checkArgument(column.getSize() >= 0); @Nonnull final RowBuffer buffer,
if (!b.get().readBit(scope.get().start(), column.getNullBit().clone())) { @Nonnull final RowCursor scope,
value.setAndGet(null); @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; 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; return Result.SUCCESS;
} }
@Override @Override
public Result readSparse(RowBuffer buffer, RowCursor edit, @Nonnull
Out<String> value) { public Result readSparse(
Utf8Span span; @Nonnull final RowBuffer buffer,
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these @Nonnull final RowCursor edit,
// cannot be converted using the 'Out' helper class unless the method is within the code being modified: @Nonnull final Out<String> value) {
Result r = this.ReadSparse(buffer, edit, out span);
value.setAndGet((r == Result.SUCCESS) ? span.toString() :) Out<Utf8String> span = new Out<>();
default Result result = this.readSparseSpan(buffer, edit, span);
return r; value.set((result == Result.SUCCESS) ? span.get().toUtf16() : null);
return result;
} }
public Result ReadSparse(Reference<RowBuffer> b, Reference<RowCursor> edit, Out<Utf8Span> value) { @Override
Result result = LayoutType.prepareSparseRead(b, edit, this.LayoutCode); @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) { if (result != Result.SUCCESS) {
value.setAndGet(null); value.set(null);
return result; return result;
} }
value.setAndGet(b.get().readSparseString(edit)); value.set(buffer.readSparseString(edit));
return Result.SUCCESS; return Result.SUCCESS;
} }
@Override @Override
public Result readVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column @Nonnull
, Out<String> value) { public Result readVariable(
Utf8Span span; @Nonnull final RowBuffer buffer,
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these @Nonnull final RowCursor scope,
// cannot be converted using the 'Out' helper class unless the method is within the code being modified: @Nonnull final LayoutColumn column,
Result r = this.ReadVariable(buffer, scope, column, out span); @Nonnull final Out<String> value) {
value.setAndGet((r == Result.SUCCESS) ? span.toString() :)
default Out<Utf8String> span = new Out<>();
return r; 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 @Override
, Out<Utf8Span> value) { @Nonnull
checkArgument(scope.get().scopeType() instanceof LayoutUDT); public Result readVariableSpan(
if (!b.get().readBit(scope.get().start(), col.getNullBit().clone())) { @Nonnull final RowBuffer buffer,
value.setAndGet(null); @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; return Result.NOT_FOUND;
} }
int varOffset = b.get().computeVariableValueOffset(scope.get().layout(), scope.get().start(), int varOffset = buffer.computeVariableValueOffset(scope.layout(), scope.start(), column.offset());
col.getOffset()); value.set(buffer.readVariableString(varOffset));
value.setAndGet(b.get().readVariableString(varOffset));
return Result.SUCCESS; return Result.SUCCESS;
} }
@Override @Override
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, @Nonnull
String value) { public Result writeFixed(
checkArgument(value != null); @Nonnull final RowBuffer buffer,
return this.writeFixed(buffer, scope, column, Utf8Span.TranscodeUtf16(value)); @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, @Override
Utf8String value) { @Nonnull
checkArgument(scope.get().scopeType() instanceof LayoutUDT); public Result writeFixed(
checkArgument(column.getSize() >= 0); @Nonnull final RowBuffer buffer,
checkArgument(value.Length == column.getSize()); @Nonnull final RowCursor scope,
if (scope.get().immutable()) { @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; return Result.INSUFFICIENT_PERMISSIONS;
} }
buffer.get().writeFixedString(scope.get().start() + column.getOffset(), value); buffer.writeFixedString(scope.start() + column.offset(), value);
buffer.get().setBit(scope.get().start(), column.getNullBit().clone()); buffer.setBit(scope.start(), column.nullBit());
return Result.SUCCESS; return Result.SUCCESS;
} }
@Override @Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, String value) { 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 @Override
public Result writeSparse(RowBuffer buffer, RowCursor edit, String value, @Nonnull
UpdateOptions options) { public Result writeSparse(RowBuffer buffer, RowCursor edit, String value, UpdateOptions options) {
checkArgument(value != null); 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) { 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: @Override
//ORIGINAL LINE: public Result WriteSparse(ref RowBuffer b, ref RowCursor edit, Utf8Span value, UpdateOptions @Nonnull
// options = UpdateOptions.Upsert) public Result writeSparse(RowBuffer buffer, RowCursor edit, Utf8String value, UpdateOptions options) {
public Result writeSparse(RowBuffer buffer, RowCursor edit, Utf8String value,
UpdateOptions options) { Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options);
Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg().clone(), options);
if (result != Result.SUCCESS) { if (result != Result.SUCCESS) {
return result; return result;
} }
buffer.get().writeSparseString(edit, value, options); buffer.writeSparseString(edit, value, options);
return Result.SUCCESS; return Result.SUCCESS;
} }
@Override @Override
public Result writeVariable(RowBuffer buffer, RowCursor scope, @Nonnull
LayoutColumn column, String value) { public Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, String value) {
checkArgument(value != null); 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, @Override
LayoutColumn column, Utf8String value) { @Nonnull
checkArgument(scope.get().scopeType() instanceof LayoutUDT); public Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, Utf8String value) {
if (scope.get().immutable()) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
if (scope.immutable()) {
return Result.INSUFFICIENT_PERMISSIONS; return Result.INSUFFICIENT_PERMISSIONS;
} }
int length = value.Length; int length = value.encodedLength();
if ((column.getSize() > 0) && (length > column.getSize())) {
if ((column.size() > 0) && (length > column.size())) {
return Result.TOO_BIG; return Result.TOO_BIG;
} }
boolean exists = buffer.get().readBit(scope.get().start(), column.getNullBit().clone()); int offset = buffer.computeVariableValueOffset(scope.layout(), scope.start(), column.offset());
int varOffset = buffer.get().computeVariableValueOffset(scope.get().layout(), scope.get().start(), boolean exists = buffer.readBit(scope.start(), column.nullBit());
column.getOffset()); int shift = buffer.writeVariableString(offset, value, exists);
int shift;
Out<Integer> tempOut_shift = new Out<Integer>(); buffer.setBit(scope.start(), column.nullBit());
buffer.get().writeVariableString(varOffset, value, exists, tempOut_shift); scope.metaOffset(scope.metaOffset() + shift);
shift = tempOut_shift.get(); scope.valueOffset(scope.valueOffset() + shift);
buffer.get().setBit(scope.get().start(), column.getNullBit().clone());
scope.get().metaOffset(scope.get().metaOffset() + shift);
scope.get().valueOffset(scope.get().valueOffset() + shift);
return Result.SUCCESS; return Result.SUCCESS;
} }
} }

View File

@@ -4,16 +4,18 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts; package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out; 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.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor; 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.checkArgument;
public final class LayoutVarInt extends LayoutType<Long> { public final class LayoutVarInt extends LayoutType<Long> {
public LayoutVarInt() { public LayoutVarInt() {
super(com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.VAR_INT, 0); super(LayoutCode.VAR_INT, 0);
} }
public boolean isFixed() { public boolean isFixed() {
@@ -24,89 +26,95 @@ public final class LayoutVarInt extends LayoutType<Long> {
return true; return true;
} }
@Nonnull
public String name() { public String name() {
return "varint"; return "varint";
} }
@Override @Override
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, @Nonnull
Out<Long> value) { public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Long> value) {
Contract.Fail("Not Implemented"); assert false : "not implemented";
value.setAndGet(0); value.set(0L);
return Result.FAILURE; return Result.FAILURE;
} }
@Override @Override
@Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Long> value) { 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) { if (result != Result.SUCCESS) {
value.setAndGet(0); value.set(0L);
return result; return result;
} }
value.setAndGet(buffer.get().ReadSparseVarInt(edit)); value.set(buffer.readSparseVarInt(edit));
return Result.SUCCESS; return Result.SUCCESS;
} }
@Override @Override
public Result readVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Long> value) { @Nonnull
checkArgument(scope.get().scopeType() instanceof LayoutUDT); public Result readVariable(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<Long> value) {
if (!buffer.get().readBit(scope.get().start(), column.getNullBit().clone())) {
value.setAndGet(0); checkArgument(scope.scopeType() instanceof LayoutUDT);
if (!buffer.readBit(scope.start(), column.nullBit())) {
value.set(0L);
return Result.NOT_FOUND; return Result.NOT_FOUND;
} }
int varOffset = buffer.get().computeVariableValueOffset(scope.get().layout(), scope.get().start(), int varOffset = buffer.computeVariableValueOffset(scope.layout(), scope.start(), column.offset());
column.getOffset()); value.set(buffer.readVariableInt(varOffset));
value.setAndGet(buffer.get().ReadVariableInt(varOffset));
return Result.SUCCESS; return Result.SUCCESS;
} }
@Override @Override
public Result WriteFixed(Reference<RowBuffer> b, Reference<RowCursor> scope, LayoutColumn col, @Nonnull
long value) { public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Long value) {
Contract.Fail("Not Implemented"); assert false : "not implemented";
return Result.FAILURE; 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 @Override
public Result WriteSparse(Reference<RowBuffer> b, Reference<RowCursor> edit, long value, @Nonnull
UpdateOptions options) { public Result writeSparse(RowBuffer buffer, RowCursor edit, Long value, UpdateOptions options) {
Result result = LayoutType.prepareSparseWrite(b, edit, this.typeArg().clone(), options);
Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options);
if (result != Result.SUCCESS) { if (result != Result.SUCCESS) {
return result; return result;
} }
b.get().writeSparseVarInt(edit, value, options); buffer.writeSparseVarInt(edit, value, options);
return Result.SUCCESS; return Result.SUCCESS;
} }
@Override @Override
public Result WriteSparse(Reference<RowBuffer> b, Reference<RowCursor> edit, long value) { @Nonnull
return WriteSparse(b, edit, value, UpdateOptions.Upsert); public Result writeSparse(RowBuffer buffer, RowCursor edit, Long value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
} }
@Override @Override
public Result WriteVariable(Reference<RowBuffer> b, Reference<RowCursor> scope, @Nonnull
LayoutColumn col, long value) { public Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, Long value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT);
if (scope.get().immutable()) { checkArgument(scope.scopeType() instanceof LayoutUDT);
if (scope.immutable()) {
return Result.INSUFFICIENT_PERMISSIONS; return Result.INSUFFICIENT_PERMISSIONS;
} }
boolean exists = b.get().readBit(scope.get().start(), col.getNullBit().clone()); boolean exists = buffer.readBit(scope.start(), column.nullBit());
int varOffset = b.get().computeVariableValueOffset(scope.get().layout(), scope.get().start(), int varOffset = buffer.computeVariableValueOffset(scope.layout(), scope.start(), column.offset());
col.getOffset()); int shift = buffer.writeVariableInt(varOffset, value, exists);
int shift;
Out<Integer> tempOut_shift = new Out<Integer>(); buffer.setBit(scope.start(), column.nullBit());
b.get().writeVariableInt(varOffset, value, exists, tempOut_shift); scope.metaOffset(scope.metaOffset() + shift);
shift = tempOut_shift.get(); scope.valueOffset(scope.valueOffset() + shift);
b.get().setBit(scope.get().start(), col.getNullBit().clone());
scope.get().metaOffset(scope.get().metaOffset() + shift);
scope.get().valueOffset(scope.get().valueOffset() + shift);
return Result.SUCCESS; return Result.SUCCESS;
} }
} }

View File

@@ -4,18 +4,18 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts; package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out; 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.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor; 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.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 final class LayoutVarUInt extends LayoutType<Long> {
public LayoutVarUInt() { public LayoutVarUInt() {
super(com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.VAR_UINT, 0); super(LayoutCode.VAR_UINT, 0);
} }
public boolean isFixed() { public boolean isFixed() {
@@ -26,104 +26,95 @@ public final class LayoutVarUInt extends LayoutType<Long> {
return true; return true;
} }
@Nonnull
public String name() { public String name() {
return "varuint"; 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 @Override
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, @Nonnull
Out<Long> value) { public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Long> value) {
Contract.Fail("Not Implemented"); assert false : "not implemented";
value.setAndGet(0); value.set(0L);
return Result.FAILURE; 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 @Override
@Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Long> value) { 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) { if (result != Result.SUCCESS) {
value.setAndGet(0); value.set(0L);
return result; return result;
} }
value.setAndGet(buffer.get().readSparseVarUInt(edit)); value.set(buffer.readSparseVarUInt(edit));
return Result.SUCCESS; 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 @Override
public Result readVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Long> value) { @Nonnull
checkArgument(scope.get().scopeType() instanceof LayoutUDT); public Result readVariable(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<Long> value) {
if (!buffer.get().readBit(scope.get().start(), column.getNullBit().clone())) {
value.setAndGet(0); checkArgument(scope.scopeType() instanceof LayoutUDT);
if (!buffer.readBit(scope.start(), column.nullBit())) {
value.set(0L);
return Result.NOT_FOUND; return Result.NOT_FOUND;
} }
int varOffset = buffer.get().computeVariableValueOffset(scope.get().layout(), scope.get().start(), int varOffset = buffer.computeVariableValueOffset(scope.layout(), scope.start(), column.offset());
column.getOffset()); value.set(buffer.readVariableUInt(varOffset));
value.setAndGet(buffer.get().ReadVariableUInt(varOffset));
return Result.SUCCESS; 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 @Override
public Result WriteFixed(Reference<RowBuffer> b, Reference<RowCursor> scope, LayoutColumn col, @Nonnull
long value) { public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Long value) {
Contract.Fail("Not Implemented"); assert false : "not implemented";
return Result.FAILURE; 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 @Override
public Result WriteSparse(Reference<RowBuffer> b, Reference<RowCursor> edit, long value, @Nonnull
UpdateOptions options) { public Result writeSparse(RowBuffer buffer, RowCursor edit, Long value, UpdateOptions options) {
Result result = prepareSparseWrite(b, edit, this.typeArg().clone(), options);
Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options);
if (result != Result.SUCCESS) { if (result != Result.SUCCESS) {
return result; return result;
} }
b.get().writeSparseVarUInt(edit, value, options); buffer.writeSparseVarUInt(edit, value, options);
return Result.SUCCESS; return Result.SUCCESS;
} }
@Override @Override
public Result WriteSparse(Reference<RowBuffer> b, Reference<RowCursor> edit, long value) { @Nonnull
return WriteSparse(b, edit, value, UpdateOptions.Upsert); 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 @Override
public Result WriteVariable(Reference<RowBuffer> b, Reference<RowCursor> scope, @Nonnull
LayoutColumn col, long value) { public Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn col, Long value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT);
if (scope.get().immutable()) { checkArgument(scope.scopeType() instanceof LayoutUDT);
if (scope.immutable()) {
return Result.INSUFFICIENT_PERMISSIONS; return Result.INSUFFICIENT_PERMISSIONS;
} }
boolean exists = b.get().readBit(scope.get().start(), col.getNullBit().clone()); final boolean exists = buffer.readBit(scope.start(), col.nullBit());
int varOffset = b.get().computeVariableValueOffset(scope.get().layout(), scope.get().start(), final int varOffset = buffer.computeVariableValueOffset(scope.layout(), scope.start(), col.offset());
col.getOffset()); final int shift = buffer.writeVariableUInt(varOffset, value, exists);
int shift;
Out<Integer> tempOut_shift = new Out<Integer>(); buffer.setBit(scope.start(), col.nullBit());
b.get().writeVariableUInt(varOffset, value, exists, tempOut_shift); scope.metaOffset(scope.metaOffset() + shift);
shift = tempOut_shift.get(); scope.valueOffset(scope.valueOffset() + shift);
b.get().setBit(scope.get().start(), col.getNullBit().clone());
scope.get().metaOffset(scope.get().metaOffset() + shift);
scope.get().valueOffset(scope.get().valueOffset() + shift);
return Result.SUCCESS; return Result.SUCCESS;
} }
} }

View File

@@ -4,49 +4,68 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts; package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.serialization.hybridrow.SchemaId; 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 { public final class SystemSchema {
/** /**
* SchemaId of the empty schema. This schema has no defined cells but can accomodate * SchemaId of the empty schema. This schema has no defined cells but can accomodate
* unschematized sparse content. * unschematized sparse content.
*/ */
public static final SchemaId EmptySchemaId = new SchemaId(2147473650); public static final SchemaId EMPTY_SCHEMA_ID = SchemaId.from(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();
/** /**
* SchemaId of HybridRow RecordIO Record Headers. * 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. * 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) { private static String FormatResourceName(Assembly assembly, String resourceName) {
return assembly.GetName().Name + "." + resourceName.replace(" ", "_").replace("\\", ".").replace("/", "."); return assembly.GetName().Name + "." + resourceName.replace(" ", "_").replace("\\", ".").replace("/", ".");
} }
*/
private static String GetEmbeddedResource(String resourceName) { static LayoutResolver loadSchema() {
Assembly assembly = Assembly.GetAssembly(RecordIOFormatter.class);
resourceName = SystemSchema.FormatResourceName(assembly, resourceName);
try (Stream resourceStream = assembly.GetManifestResourceStream(resourceName)) {
if (resourceStream == null) {
return null;
}
try (InputStreamReader reader = new InputStreamReader(resourceStream)) { final String json;
return reader.ReadToEnd();
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; 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}. * Describes the desired behavior when writing a {@link LayoutType}.
*/ */
public enum UpdateOptions { public enum UpdateOptions {
None(0), NONE(0),
/** /**
* Overwrite an existing value. * 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 * replaced inline. The remainder of the row is resized to accomodate either an increase or decrease
* in required space. * in required space.
*/ */
Update(1), UPDATE(1),
/** /**
* Insert a new value. * Insert a new value
* <p> * <p>
* An existing value is assumed NOT to exist at the offset provided. The new value is * An existing value is assumed NOT to exist at the offset provided. The new value is inserted immediately at the
* inserted immediately at the offset. The remainder of the row is resized to accomodate either an * offset. The remainder of the row is resized to accommodate either an increase or decrease in required space.
* 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> * <p>
* If a value exists, then this operation becomes {@link Update}, otherwise it becomes * If a value exists, then this operation becomes {@link #UPDATE}, otherwise it becomes {@link #INSERT}.
* {@link Insert}.
*/ */
Upsert(3), UPSERT(3),
/** /**
* Insert a new value moving existing values to the right. * Insert a new value moving existing values to the right.
* <p> * <p>
* Within an array scope, inserts a new value immediately at the index moving all subsequent * 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; public static final int BYTES = Integer.BYTES;
private static java.util.HashMap<Integer, UpdateOptions> mappings;
private static Int2ObjectMap<UpdateOptions> mappings;
private int value; private int value;
UpdateOptions(int value) { UpdateOptions(int value) {
@@ -55,19 +55,19 @@ public enum UpdateOptions {
mappings().put(value, this); mappings().put(value, this);
} }
public int value() {
return this.value;
}
public static UpdateOptions from(int value) { public static UpdateOptions from(int value) {
return mappings().get(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) { if (mappings == null) {
synchronized (UpdateOptions.class) { synchronized (UpdateOptions.class) {
if (mappings == null) { if (mappings == null) {
mappings = new HashMap<>(); mappings = new Int2ObjectOpenHashMap<>();
} }
} }
} }

View File

@@ -3,35 +3,35 @@
package com.azure.data.cosmos.serialization.hybridrow.recordio; 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 { 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: private int crc32;
//ORIGINAL LINE: public Record(int length, uint crc32) private int length;
public Record(int length, int crc32) { public Record(int length, int crc32) {
this.Length = length; this.length = length;
this.Crc32 = crc32; this.crc32 = crc32;
} }
public Record clone() { public int crc32() {
Record varCopy = new Record(); return this.crc32;
}
varCopy.Length = this.Length; public Record crc32(int value) {
varCopy.Crc32 = this.Crc32; 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; import com.azure.data.cosmos.serialization.hybridrow.layouts.SystemSchema;
public final class RecordIOFormatter { 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) { public static Result FormatRecord(ReadOnlyMemory<Byte> body, Out<RowBuffer> row) {
return FormatRecord(body, row, null); 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: //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: resizer = resizer != null ? resizer : DefaultSpanResizer<byte>.Default; //ORIGINAL LINE: resizer = resizer != null ? resizer : DefaultSpanResizer<byte>.Default;
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: //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: uint crc32 = Crc32.Update(0, body.Span); //ORIGINAL LINE: uint crc32 = Crc32.Update(0, body.Span);
int crc32 = Crc32.Update(0, body.Span); int crc32 = Crc32.Update(0, body.Span);
Record record = new Record(body.Length, crc32); 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()); RecordSerializer.Write, row.clone());
} }
@@ -51,11 +52,11 @@ public final class RecordIOFormatter {
//ORIGINAL LINE: resizer = resizer != null ? resizer : DefaultSpanResizer<byte>.Default; //ORIGINAL LINE: resizer = resizer != null ? resizer : DefaultSpanResizer<byte>.Default;
resizer = resizer != null ? resizer : DefaultSpanResizer < Byte >.Default; resizer = resizer != null ? resizer : DefaultSpanResizer < Byte >.Default;
int estimatedSize = int estimatedSize =
HybridRowHeader.BYTES + RecordIOFormatter.SegmentLayout.getSize() + segment.Comment == null ? null : HybridRowHeader.BYTES + RecordIOFormatter.SEGMENT_LAYOUT.getSize() + segment.comment() == null ? null :
segment.Comment.length() != null ? segment.Comment.length() : 0 + segment.SDL == null ? null : segment.comment().length() != null ? segment.comment().length() : 0 + segment.sdl() == null ? null :
segment.SDL.length() != null ? segment.SDL.length() : 0 + 20; 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()); 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, private static <T> Result FormatObject(ISpanResizer<Byte> resizer, int initialCapacity, Layout layout, T obj,
RowWriter.WriterFunc<T> writer, Out<RowBuffer> row) { RowWriter.WriterFunc<T> writer, Out<RowBuffer> row) {
row.setAndGet(new RowBuffer(initialCapacity, resizer)); 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); Result r = RowWriter.WriteBuffer(row.clone(), obj, writer);
if (r != Result.SUCCESS) { if (r != Result.SUCCESS) {
row.setAndGet(null); 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.SchemaId;
import com.azure.data.cosmos.serialization.hybridrow.io.RowReader; import com.azure.data.cosmos.serialization.hybridrow.io.RowReader;
import com.azure.data.cosmos.serialization.hybridrow.layouts.SystemSchema; 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 { 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]; private State state = State.values()[0];
/** /**
* True if a valid segment has been parsed. * Processes one buffers worth of data possibly advancing the parser state
*/
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.
* *
* @param buffer The buffer to consume. * @param buffer1 The buffer to consume
* @param type Indicates the type of Hybrid Row produced in <paramref name="record" />. * @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 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 * @param need The smallest number of bytes needed to advanced the parser state further
* recommended that Process not be called again until at least this number of bytes are available. * <p>
* @param consumed The number of bytes consumed from the input buffer. This number may be less * It is recommended that this method not be called again until at least this number of bytes are
* than the total buffer size if the parser moved to a new state. * available.
* @return {@link azure.data.cosmos.serialization.hybridrow.Result.Success} if no error * @param consumed The number of bytes consumed from the input buffer
* has occurred, otherwise a valid * <p>
* {@link azure.data.cosmos.serialization.hybridrow.Result} of the last error encountered * This number may be less than the total buffer size if the parser moved to a new state.
* during parsing. * @return {@link Result#SUCCESS} if no error has occurred;, otherwise the {@link Result} of the last error
* encountered during parsing.
* <p> * <p>
* > * >
*/ */
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: @Nonnull
//ORIGINAL LINE: public Result Process(Memory<byte> buffer, out ProductionType type, out Memory<byte> record, out public Result process(
// int need, out int consumed) @Nonnull final ByteBuf buffer,
public Result Process(Memory<Byte> buffer, Out<ProductionType> type, @Nonnull final Out<ProductionType> type,
Out<Memory<Byte>> record, Out<Integer> need, @Nonnull final Out<ByteBuf> record,
Out<Integer> consumed) { @Nonnull final Out<Integer> need,
Result r = Result.FAILURE; @Nonnull final Out<Integer> consumed) {
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: Memory<byte> b = buffer; Result result = Result.FAILURE;
Memory<Byte> b = buffer; type.set(ProductionType.NONE);
type.setAndGet(ProductionType.None); record.set(null);
record.setAndGet(null);
final int start = buffer.readerIndex();
switch (this.state) { 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: // TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
case NeedSegmentLength: { // goto case State.NeedSegmentLength;
int minimalSegmentRowSize = HybridRowHeader.BYTES + RecordIOFormatter.SegmentLayout.getSize();
if (b.Length < minimalSegmentRowSize) { case NEED_SEGMENT_LENGTH: {
need.setAndGet(minimalSegmentRowSize);
consumed.setAndGet(buffer.Length - b.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; return Result.INSUFFICIENT_BUFFER;
} }
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: ByteBuf span = buffer.slice(buffer.readerIndex(), minimalSegmentRowSize);
//ORIGINAL LINE: Span<byte> span = b.Span.Slice(0, minimalSegmentRowSize); RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.layoutResolver);
Span<Byte> span = b.Span.Slice(0, minimalSegmentRowSize);
RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.LayoutResolver);
Reference<RowBuffer> tempReference_row = Reference<RowBuffer> tempReference_row =
new Reference<RowBuffer>(row); new Reference<RowBuffer>(row);
RowReader reader = new RowReader(tempReference_row); RowReader reader = new RowReader(tempReference_row);
@@ -89,29 +87,29 @@ public final class RecordIOParser {
new Reference<RowReader>(reader); new Reference<RowReader>(reader);
Out<Segment> tempOut_segment = Out<Segment> tempOut_segment =
new Out<Segment>(); new Out<Segment>();
r = SegmentSerializer.Read(tempReference_reader, tempOut_segment); result = SegmentSerializer.Read(tempReference_reader, tempOut_segment);
this.segment = tempOut_segment.get(); this.segment = tempOut_segment.get();
reader = tempReference_reader.get(); reader = tempReference_reader.get();
if (r != Result.SUCCESS) { if (result != Result.SUCCESS) {
break; break;
} }
this.state = State.NeedSegment; this.state = State.NEED_SEGMENT;
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java: // TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
goto case State.NeedSegment goto case State.NEED_SEGMENT
} }
case NeedSegment: { case NEED_SEGMENT: {
if (b.Length < this.segment.Length) { if (buffer.Length < this.segment.length()) {
need.setAndGet(this.segment.Length); need.set(this.segment.length());
consumed.setAndGet(buffer.Length - b.Length); consumed.set(buffer.Length - buffer.Length);
return Result.INSUFFICIENT_BUFFER; return Result.INSUFFICIENT_BUFFER;
} }
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: //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); //ORIGINAL LINE: Span<byte> span = b.Span.Slice(0, this.segment.Length);
Span<Byte> span = b.Span.Slice(0, this.segment.Length); Span<Byte> span = buffer.Span.Slice(0, this.segment.length());
RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.LayoutResolver); RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.layoutResolver);
Reference<RowBuffer> tempReference_row2 = Reference<RowBuffer> tempReference_row2 =
new Reference<RowBuffer>(row); new Reference<RowBuffer>(row);
RowReader reader = new RowReader(tempReference_row2); RowReader reader = new RowReader(tempReference_row2);
@@ -120,26 +118,26 @@ public final class RecordIOParser {
new Reference<RowReader>(reader); new Reference<RowReader>(reader);
Out<Segment> tempOut_segment2 Out<Segment> tempOut_segment2
= new Out<Segment>(); = new Out<Segment>();
r = SegmentSerializer.Read(tempReference_reader2, tempOut_segment2); result = SegmentSerializer.Read(tempReference_reader2, tempOut_segment2);
this.segment = tempOut_segment2.get(); this.segment = tempOut_segment2.get();
reader = tempReference_reader2.get(); reader = tempReference_reader2.get();
if (r != Result.SUCCESS) { if (result != Result.SUCCESS) {
break; break;
} }
record.setAndGet(b.Slice(0, span.Length)); record.set(buffer.Slice(0, span.Length));
b = b.Slice(span.Length); buffer = buffer.Slice(span.Length);
need.setAndGet(0); need.set(0);
this.state = State.NeedHeader; this.state = State.NEED_HEADER;
consumed.setAndGet(buffer.Length - b.Length); consumed.set(buffer.Length - buffer.Length);
type.setAndGet(ProductionType.Segment); type.set(ProductionType.SEGMENT);
return Result.SUCCESS; return Result.SUCCESS;
} }
case NeedHeader: { case NEED_HEADER: {
if (b.Length < HybridRowHeader.BYTES) { if (buffer.Length < HybridRowHeader.BYTES) {
need.setAndGet(HybridRowHeader.BYTES); need.set(HybridRowHeader.BYTES);
consumed.setAndGet(buffer.Length - b.Length); consumed.set(buffer.Length - buffer.Length);
return Result.INSUFFICIENT_BUFFER; 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 - // 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 // these cannot be converted using the 'Out' helper class unless the method is within the code
// being modified: // being modified:
MemoryMarshal.TryRead(b.Span, out header); MemoryMarshal.TryRead(buffer.Span, out header);
if (header.Version != HybridRowVersion.V1) { if (header.Version != HybridRowVersion.V1) {
r = Result.INVALID_ROW; result = Result.INVALID_ROW;
break; break;
} }
if (SchemaId.opEquals(header.SchemaId, if (SchemaId.opEquals(header.SchemaId,
SystemSchema.SegmentSchemaId)) { SystemSchema.SEGMENT_SCHEMA_ID)) {
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java: // 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, if (SchemaId.opEquals(header.SchemaId,
SystemSchema.RecordSchemaId)) { SystemSchema.RECORD_SCHEMA_ID)) {
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java: // 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; break;
} }
case NeedRecord: { case NEED_RECORD: {
int minimalRecordRowSize = HybridRowHeader.BYTES + RecordIOFormatter.RecordLayout.getSize(); int minimalRecordRowSize = HybridRowHeader.BYTES + RecordIOFormatter.RECORD_LAYOUT.size();
if (b.Length < minimalRecordRowSize) { if (buffer.Length < minimalRecordRowSize) {
need.setAndGet(minimalRecordRowSize); need.set(minimalRecordRowSize);
consumed.setAndGet(buffer.Length - b.Length); consumed.set(buffer.Length - buffer.Length);
return Result.INSUFFICIENT_BUFFER; return Result.INSUFFICIENT_BUFFER;
} }
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: Span<byte> span = b.Span.Slice(0, minimalRecordRowSize); //ORIGINAL LINE: Span<byte> span = b.Span.Slice(0, minimalRecordRowSize);
Span<Byte> span = b.Span.Slice(0, minimalRecordRowSize); Span<Byte> span = buffer.Span.Slice(0, minimalRecordRowSize);
RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.LayoutResolver); RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.layoutResolver);
Reference<RowBuffer> tempReference_row3 = Reference<RowBuffer> tempReference_row3 =
new Reference<RowBuffer>(row); new Reference<RowBuffer>(row);
RowReader reader = new RowReader(tempReference_row3); RowReader reader = new RowReader(tempReference_row3);
row = tempReference_row3.get(); row = tempReference_row3.get();
Reference<RowReader> tempReference_reader3 = new Reference<RowReader>(reader); Reference<RowReader> tempReference_reader3 = new Reference<RowReader>(reader);
Out<Record> tempOut_record = new Out<Record>(); 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(); this.record = tempOut_record.get();
reader = tempReference_reader3.get(); reader = tempReference_reader3.get();
if (r != Result.SUCCESS) { if (result != Result.SUCCESS) {
break; break;
} }
b = b.Slice(span.Length); buffer = buffer.Slice(span.Length);
this.state = State.NeedRow; this.state = State.NEED_ROW;
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java: // TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
goto case State.NeedRow goto case State.NEED_ROW
} }
case NeedRow: { case NEED_ROW: {
if (b.Length < this.record.Length) { if (buffer.Length < this.record.length()) {
need.setAndGet(this.record.Length); need.set(this.record.length());
consumed.setAndGet(buffer.Length - b.Length); consumed.set(buffer.Length - buffer.Length);
return Result.INSUFFICIENT_BUFFER; 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. // Validate that the record has not been corrupted.
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: uint crc32 = Crc32.Update(0, record.Span); //ORIGINAL LINE: uint crc32 = Crc32.Update(0, record.Span);
int crc32 = Crc32.Update(0, record.get().Span); int crc32 = Crc32.Update(0, record.get().Span);
if (crc32 != this.record.Crc32) { if (crc32 != this.record.crc32()) {
r = Result.INVALID_ROW; result = Result.INVALID_ROW;
break; break;
} }
b = b.Slice(this.record.Length); buffer = buffer.Slice(this.record.length());
need.setAndGet(0); need.set(0);
this.state = State.NeedHeader; this.state = State.NEED_HEADER;
consumed.setAndGet(buffer.Length - b.Length); consumed.set(buffer.Length - buffer.Length);
type.setAndGet(ProductionType.Record); type.set(ProductionType.RECORD);
return Result.SUCCESS; return Result.SUCCESS;
} }
} }
this.state = State.Error; this.state = State.ERROR;
need.setAndGet(0); need.set(0);
consumed.setAndGet(buffer.Length - b.Length); consumed.set(buffer.Length - buffer.Length);
return r; 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(); * If a valid segment has been parsed then current active segment, otherwise undefined.
varCopy.record = this.record.clone(); */
public Segment segment() {
return varCopy; checkState(this.haveSegment());
return this.segment;
} }
/** /**
@@ -250,40 +253,41 @@ public final class RecordIOParser {
/** /**
* No hybrid row was produced. The parser needs more data. * No hybrid row was produced. The parser needs more data.
*/ */
None(0), NONE(0),
/** /**
* A new segment row was produced. * A new segment row was produced.
*/ */
Segment(1), SEGMENT(1),
/** /**
* A record in the current segment was produced. * A record in the current segment was produced.
*/ */
Record(2); RECORD(2);
public static final int SIZE = java.lang.Integer.SIZE; public static final int BYTES = Integer.BYTES;
private static java.util.HashMap<Integer, ProductionType> mappings;
private int intValue; private static Int2ObjectMap<ProductionType> mappings;
private int value;
ProductionType(int value) { ProductionType(int value) {
intValue = value; this.value = value;
getMappings().put(value, this); mappings().put(value, this);
} }
public int getValue() { public int value() {
return intValue; return this.value;
} }
public static ProductionType forValue(int value) { public static ProductionType from(int value) {
return getMappings().get(value); return mappings().get(value);
} }
private static java.util.HashMap<Integer, ProductionType> getMappings() { private static Int2ObjectMap<ProductionType> mappings() {
if (mappings == null) { if (mappings == null) {
synchronized (ProductionType.class) { synchronized (ProductionType.class) {
if (mappings == null) { 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. * The states for the internal state machine.
* Note: numerical ordering of these states matters. * 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 { private enum State {
Start((byte)0), // Start: no buffers have yet been provided to the parser. STATE(
Error(((byte)0) + 1), // Unrecoverable parse error encountered. (byte) 0, "Start: no buffers have yet been provided to the parser"),
NeedSegmentLength(((byte)0) + 2), // Parsing segment header length ERROR(
NeedSegment(((byte)0) + 3), // Parsing segment header (byte) 1, "Unrecoverable parse error encountered"),
NeedHeader(((byte)0) + 4), // Parsing HybridRow header NEED_SEGMENT_LENGTH(
NeedRecord(((byte)0) + 5), // Parsing record header (byte) 2, "Parsing segment header length"),
NeedRow(((byte)0) + 6); // Parsing row body 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; public static final int BYTES = Byte.SIZE;
private static java.util.HashMap<Byte, State> mappings;
private byte byteValue;
State(byte value) { private static Byte2ObjectMap<State> mappings;
byteValue = value; private final String description;
getMappings().put(value, this); private final byte value;
State(byte value, String description) {
this.description = description;
this.value = value;
mappings().put(value, this);
} }
public byte getValue() { public String description() {
return byteValue; return this.description;
} }
public static State forValue(byte value) { public byte value() {
return getMappings().get(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) { if (mappings == null) {
synchronized (State.class) { synchronized (State.class) {
if (mappings == null) { 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: //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 //ORIGINAL LINE: Result r = parser.Process(avail, out RecordIOParser.ProductionType prodType, out
// Memory<byte> record, out need, out int consumed); // 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(); consumed = tempOut_consumed.get();
need = tempOut_need.get(); need = tempOut_need.get();
record = tempOut_record.get(); record = tempOut_record.get();
@@ -145,7 +145,7 @@ public final class RecordIOStream {
} }
// Validate the Segment // Validate the Segment
if (prodType == RecordIOParser.ProductionType.Segment) { if (prodType == RecordIOParser.ProductionType.SEGMENT) {
checkState(!record.IsEmpty); checkState(!record.IsEmpty);
r = visitSegment == null ? null : visitSegment.invoke(record) != null ? r = visitSegment == null ? null : visitSegment.invoke(record) != null ?
visitSegment.invoke(record) : Result.SUCCESS; visitSegment.invoke(record) : Result.SUCCESS;
@@ -155,7 +155,7 @@ public final class RecordIOStream {
} }
// Consume the record. // Consume the record.
if (prodType == RecordIOParser.ProductionType.Record) { if (prodType == RecordIOParser.ProductionType.RECORD) {
checkState(!record.IsEmpty); checkState(!record.IsEmpty);
r = visitRecord.invoke(record); r = visitRecord.invoke(record);

View File

@@ -4,36 +4,52 @@
package com.azure.data.cosmos.serialization.hybridrow.recordio; package com.azure.data.cosmos.serialization.hybridrow.recordio;
import com.azure.data.cosmos.core.Out; 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.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 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. @Nonnull
switch (reader.get().getPath().toString()) { 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": 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; 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; break;
} }
} }
@@ -41,14 +57,12 @@ public final class RecordSerializer {
return Result.SUCCESS; return Result.SUCCESS;
} }
public static Result Write(Reference<RowWriter> writer, TypeArgument typeArg, Record obj) { @Nonnull
Result r; public static Result write(RowWriter writer, TypeArgument typeArg, Record record) {
r = writer.get().WriteInt32("length", obj.Length); Result result = writer.writeInt32(new UtfAnyString("length"), record.length());
if (r != Result.SUCCESS) { if (result != Result.SUCCESS) {
return r; return result;
} }
return writer.writeUInt32(new UtfAnyString("crc32"), record.crc32());
r = writer.get().WriteUInt32("crc32", obj.Crc32);
return r;
} }
} }

View File

@@ -3,34 +3,27 @@
package com.azure.data.cosmos.serialization.hybridrow.recordio; 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 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) { public Segment(String comment, String sdl) {
this.Length = 0; this.comment = comment;
this.Comment = comment; this.sdl = sdl;
this.SDL = sdl; this.length = 0;
} }
public Segment clone() { public String comment() {
Segment varCopy = new Segment(); return this.comment;
}
varCopy.Length = this.Length; public int length() {
varCopy.Comment = this.Comment; return this.length;
varCopy.SDL = this.SDL; }
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 // If the RowBuffer isn't big enough to contain the rest of the header, then just
// return the length. // return the length.
if (reader.get().length() < obj.get().Length) { if (reader.get().length() < obj.get().length()) {
return Result.SUCCESS; return Result.SUCCESS;
} }
@@ -74,15 +74,15 @@ public final class SegmentSerializer {
public static Result Write(Reference<RowWriter> writer, TypeArgument typeArg, Segment obj) { public static Result Write(Reference<RowWriter> writer, TypeArgument typeArg, Segment obj) {
Result r; Result r;
if (obj.Comment != null) { if (obj.comment() != null) {
r = writer.get().WriteString("comment", obj.Comment); r = writer.get().WriteString("comment", obj.comment());
if (r != Result.SUCCESS) { if (r != Result.SUCCESS) {
return r; return r;
} }
} }
if (obj.SDL != null) { if (obj.sdl() != null) {
r = writer.get().WriteString("sdl", obj.SDL); r = writer.get().WriteString("sdl", obj.sdl());
if (r != Result.SUCCESS) { if (r != Result.SUCCESS) {
return r; return r;
} }

View File

@@ -6,6 +6,7 @@ package com.azure.data.cosmos.serialization.hybridrow.schemas;
import com.azure.data.cosmos.core.Json; import com.azure.data.cosmos.core.Json;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.Optional; import java.util.Optional;
public class Namespace { 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. * 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 * 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. * 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; return this.schemas;
} }

View File

@@ -73,7 +73,7 @@ public class Schema {
checkNotNull(ns, "expected non-null ns"); checkNotNull(ns, "expected non-null ns");
checkArgument(ns.schemas().contains(this)); 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: //C# TO JAVA CONVERTER WARNING: Java has no equivalent to C# 'private protected' access:
//ORIGINAL LINE: private protected LayoutResolverNamespace DefaultResolver = (LayoutResolverNamespace) //ORIGINAL LINE: private protected LayoutResolverNamespace DefaultResolver = (LayoutResolverNamespace)
// SystemSchema.LayoutResolver; // 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: // 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)> // private protected async Task<(List<Dictionary<Utf8String, object>>, LayoutResolverNamespace)>

View File

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

View File

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