Progressed on port from dotnet to java

This commit is contained in:
David Noble
2019-08-27 22:49:03 -07:00
parent 28c8eadd01
commit 20ad953fcd
4 changed files with 29 additions and 46 deletions

View File

@@ -11,6 +11,7 @@ import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutEndScope;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutScope; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutScope;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTuple; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTuple;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutType; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutType;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTypes;
import com.azure.data.cosmos.serialization.hybridrow.layouts.StringToken; import com.azure.data.cosmos.serialization.hybridrow.layouts.StringToken;
import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument; import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument;
import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgumentList; import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgumentList;
@@ -26,7 +27,7 @@ public final class RowCursor {
/** /**
* For types with generic parameters (e.g. {@link LayoutTuple}, the type parameters. * For types with generic parameters (e.g. {@link LayoutTuple}, the type parameters.
*/ */
public TypeArgumentList cellTypeArgs = new TypeArgumentList(); public TypeArgumentList cellTypeArgs;
/** /**
* If true, this scope is an unique index scope whose index will be built after its items are written. * If true, this scope is an unique index scope whose index will be built after its items are written.
*/ */
@@ -54,41 +55,39 @@ public final class RowCursor {
private Layout layout; private Layout layout;
private int metaOffset; private int metaOffset;
private LayoutScope scopeType; private LayoutScope scopeType;
private TypeArgumentList scopeTypeArgs = new TypeArgumentList(); private TypeArgumentList scopeTypeArgs;
private int start; private int start;
private int valueOffset; private int valueOffset;
private UtfAnyString writePath; private UtfAnyString writePath;
private StringToken writePathToken = new StringToken(); private StringToken writePathToken = new StringToken();
public static RowCursor Create(Reference<RowBuffer> row) { public static RowCursor Create(RowBuffer row) {
final SchemaId schemaId = row.get().ReadSchemaId(1); final SchemaId schemaId = row.ReadSchemaId(1);
final Layout layout = row.get().resolver().Resolve(schemaId); final Layout layout = row.resolver().Resolve(schemaId);
final int sparseSegmentOffset = row.get().computeVariableValueOffset(layout, HybridRowHeader.SIZE, final int sparseSegmentOffset = row.computeVariableValueOffset(layout, HybridRowHeader.SIZE, layout.numVariable());
layout.numVariable());
final RowCursor cursor = new RowCursor() return new RowCursor()
.layout(layout) .layout(layout)
.scopeType(LayoutType.UDT) .scopeType(LayoutTypes.UDT)
.scopeTypeArgs(new TypeArgumentList(schemaId)) .scopeTypeArgs(new TypeArgumentList(schemaId))
.start(HybridRowHeader.SIZE) .start(HybridRowHeader.SIZE)
.metaOffset(sparseSegmentOffset) .metaOffset(sparseSegmentOffset)
.valueOffset(sparseSegmentOffset); .valueOffset(sparseSegmentOffset);
return cursor;
} }
public static RowCursor Create(RowBuffer row) { public static RowCursor CreateForAppend(RowBuffer row) {
final SchemaId schemaId = row.ReadSchemaId(1); final SchemaId schemaId = row.ReadSchemaId(1);
final Layout layout = row.Resolver.Resolve(schemaId); final Layout layout = row.resolver().Resolve(schemaId);
final int sparseSegmentOffset = row.computeVariableValueOffset(layout, HybridRowHeader.Size,
layout.NumVariable);
return new RowCursor() return new RowCursor()
.layout(layout) .layout(layout)
.scopeType(LayoutType.UDT) .scopeType(LayoutTypes.UDT)
.scopeTypeArgs(new TypeArgumentList(schemaId, HybridRowHeader.SIZE, sparseSegmentOffset, sparseSegmentOffset); .scopeTypeArgs(new TypeArgumentList(schemaId))
.start(HybridRowHeader.SIZE)
.metaOffset(row.length())
.valueOffset(row.length());
} }
/** /**
@@ -103,18 +102,6 @@ public final class RowCursor {
return this; return this;
} }
// TODO: C# TO JAVA CONVERTER: 'ref return' methods are not converted by C# to Java Converter:
// public static ref RowCursor CreateForAppend(ref RowBuffer row, out RowCursor cursor)
// {
// SchemaId schemaId = row.ReadSchemaId(1);
// Layout layout = row.Resolver.Resolve(schemaId);
// cursor = new RowCursor { layout = layout, scopeType = LayoutType.UDT, scopeTypeArgs = new
// TypeArgumentList(schemaId), start = HybridRowHeader.Size, metaOffset = row.Length, valueOffset = row
// .Length};
//
// return ref cursor;
// }
/** /**
* If {@code true}, this scope's nested fields cannot be updated individually * If {@code true}, this scope's nested fields cannot be updated individually
* <p> * <p>
@@ -213,19 +200,19 @@ public final class RowCursor {
} }
TypeArgument scopeTypeArg = (this.scopeType() instanceof LayoutEndScope) TypeArgument scopeTypeArg = (this.scopeType() instanceof LayoutEndScope)
? new TypeArgument() ? TypeArgument.NONE
: new TypeArgument(this.scopeType(), this.scopeTypeArgs().clone()); : new TypeArgument(this.scopeType(), this.scopeTypeArgs());
TypeArgument typeArg = (this.cellType == null) || (this.cellType instanceof LayoutEndScope) TypeArgument typeArg = (this.cellType == null) || (this.cellType instanceof LayoutEndScope)
? new TypeArgument() ? TypeArgument.NONE
: new TypeArgument(this.cellType, this.cellTypeArgs.clone()); : new TypeArgument(this.cellType, this.cellTypeArgs);
String pathOrIndex = this.writePath().isNull() ? String.valueOf(this.index()) : this.writePath().toString(); String pathOrIndex = this.writePath().isNull() ? String.valueOf(this.index()) : this.writePath().toString();
return lenientFormat("%s[%s] : %s@%s/%s%s", return lenientFormat("%s[%s] : %s@%s/%s%s",
scopeTypeArg.clone(), scopeTypeArg,
pathOrIndex, pathOrIndex,
typeArg.clone(), typeArg,
this.metaOffset(), this.metaOffset(),
this.valueOffset(), this.valueOffset(),
this.immutable() ? " immutable" : ""); this.immutable() ? " immutable" : "");

View File

@@ -6,6 +6,7 @@ package com.azure.data.cosmos.serialization.hybridrow.io;
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.Reference;
import com.azure.data.cosmos.core.Utf8String;
import com.azure.data.cosmos.core.UtfAnyString; import com.azure.data.cosmos.core.UtfAnyString;
import com.azure.data.cosmos.serialization.hybridrow.Float128; import com.azure.data.cosmos.serialization.hybridrow.Float128;
import com.azure.data.cosmos.serialization.hybridrow.NullValue; import com.azure.data.cosmos.serialization.hybridrow.NullValue;
@@ -51,10 +52,6 @@ import java.util.UUID;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
///#pragma warning disable CA1034 // Nested types should not be visible
/** /**
* A forward-only, streaming, field reader for {@link RowBuffer}. * A forward-only, streaming, field reader for {@link RowBuffer}.
* <p> * <p>
@@ -66,10 +63,6 @@ import static com.google.common.base.Preconditions.checkState;
* Modifying a {@link RowBuffer} invalidates any reader or child reader associated with it. In * Modifying a {@link RowBuffer} invalidates any reader or child reader associated with it. In
* general {@link RowBuffer}'s should not be mutated while being enumerated. * general {@link RowBuffer}'s should not be mutated while being enumerated.
*/ */
//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 ref struct RowReader
//C# TO JAVA CONVERTER WARNING: Java has no equivalent to the C# ref struct:
public final class RowReader { public final class RowReader {
private int columnIndex; private int columnIndex;

View File

@@ -7,9 +7,6 @@ package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Utf8String; import com.azure.data.cosmos.core.Utf8String;
import com.azure.data.cosmos.serialization.hybridrow.schemas.StorageKind; import com.azure.data.cosmos.serialization.hybridrow.schemas.StorageKind;
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [DebuggerDisplay("{FullPath + \": \" + Type.Name + TypeArgs.ToString()}")] public sealed class
// LayoutColumn
public final class LayoutColumn { public final class LayoutColumn {
/** /**
* For bool fields, 0-based index into the bit mask for the bool value. * For bool fields, 0-based index into the bit mask for the bool value.

View File

@@ -8,9 +8,15 @@ import static com.google.common.base.Preconditions.checkNotNull;
public final class TypeArgument { public final class TypeArgument {
public static final TypeArgument NONE = new TypeArgument();
private final LayoutType type; private final LayoutType type;
private final TypeArgumentList typeArgs; private final TypeArgumentList typeArgs;
private TypeArgument() {
this.type = null;
this.typeArgs = null;
}
/** /**
* Initializes a new instance of the {@link TypeArgument} struct. * Initializes a new instance of the {@link TypeArgument} struct.
* *