Progressed on port from dotnet to java

This commit is contained in:
David Noble
2019-09-06 02:19:28 -07:00
parent 782a52d8cb
commit 56fb5163ca
13 changed files with 693 additions and 566 deletions

View File

@@ -52,7 +52,7 @@ public final class RowCursor implements Cloneable {
final SchemaId schemaId = row.readSchemaId(1);
final Layout layout = row.resolver().resolve(schemaId);
final int sparseSegmentOffset = row.ComputeVariableValueOffset(layout, HybridRowHeader.BYTES, layout.numVariable());
final int sparseSegmentOffset = row.computeVariableValueOffset(layout, HybridRowHeader.BYTES, layout.numVariable());
return new RowCursor()
.layout(layout)

View File

@@ -120,7 +120,7 @@ public final class RowCursors {
if (childScope.scopeType().isSizedScope()) {
edit.endOffset(childScope.metaOffset());
} else {
edit.endOffset(childScope.metaOffset() + (LayoutCode.SIZE / Byte.SIZE)); // move past end of scope marker
edit.endOffset(childScope.metaOffset() + LayoutCode.BYTES); // move past end of scope marker
}
}
}

View File

@@ -386,7 +386,7 @@ public final class RowWriter {
new Reference<RowCursor>(this.cursor);
Out<RowCursor> tempOut_nestedScope =
new Out<RowCursor>();
this.row.writeSparseObject(tempRef_cursor, scopeType, UpdateOptions.Upsert, tempOut_nestedScope);
this.row.writeSparseObject(tempRef_cursor, scopeType, UpdateOptions.Upsert);
nestedScope = tempOut_nestedScope.get();
this.cursor = tempRef_cursor.argValue;
break;
@@ -398,7 +398,7 @@ public final class RowWriter {
new Reference<RowCursor>(this.cursor);
Out<RowCursor> tempOut_nestedScope2 =
new Out<RowCursor>();
this.row.WriteSparseArray(tempRef_cursor2, scopeType, UpdateOptions.Upsert, tempOut_nestedScope2);
this.row.writeSparseArray(tempRef_cursor2, scopeType, UpdateOptions.Upsert);
nestedScope = tempOut_nestedScope2.get();
this.cursor = tempRef_cursor2.argValue;
break;
@@ -424,7 +424,7 @@ public final class RowWriter {
new Reference<RowCursor>(this.cursor);
Out<RowCursor> tempOut_nestedScope4 =
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);
nestedScope = tempOut_nestedScope4.get();
this.cursor = tempRef_cursor4.argValue;
@@ -438,8 +438,8 @@ public final class RowWriter {
new Reference<RowCursor>(this.cursor);
Out<RowCursor> tempOut_nestedScope5 =
new Out<RowCursor>();
this.row.WriteTypedTuple(tempRef_cursor5, scopeType, typeArg.typeArgs().clone(),
UpdateOptions.Upsert, tempOut_nestedScope5);
this.row.writeTypedTuple(tempRef_cursor5, scopeType, typeArg.typeArgs().clone(),
UpdateOptions.Upsert);
nestedScope = tempOut_nestedScope5.get();
this.cursor = tempRef_cursor5.argValue;
@@ -452,8 +452,8 @@ public final class RowWriter {
new Reference<RowCursor>(this.cursor);
Out<RowCursor> tempOut_nestedScope6 =
new Out<RowCursor>();
this.row.WriteTypedTuple(tempRef_cursor6, scopeType, typeArg.typeArgs().clone(),
UpdateOptions.Upsert, tempOut_nestedScope6);
this.row.writeTypedTuple(tempRef_cursor6, scopeType, typeArg.typeArgs().clone(),
UpdateOptions.Upsert);
nestedScope = tempOut_nestedScope6.get();
this.cursor = tempRef_cursor6.argValue;
@@ -466,8 +466,8 @@ public final class RowWriter {
new Reference<RowCursor>(this.cursor);
Out<RowCursor> tempOut_nestedScope7 =
new Out<RowCursor>();
this.row.WriteTypedTuple(tempRef_cursor7, scopeType, typeArg.typeArgs().clone(),
UpdateOptions.Upsert, tempOut_nestedScope7);
this.row.writeTypedTuple(tempRef_cursor7, scopeType, typeArg.typeArgs().clone(),
UpdateOptions.Upsert);
nestedScope = tempOut_nestedScope7.get();
this.cursor = tempRef_cursor7.argValue;
@@ -481,7 +481,7 @@ public final class RowWriter {
Out<RowCursor> tempOut_nestedScope8 =
new Out<RowCursor>();
this.row.writeNullable(tempRef_cursor8, scopeType, typeArg.typeArgs().clone(),
UpdateOptions.Upsert, func != null, tempOut_nestedScope8);
UpdateOptions.Upsert, func != null);
nestedScope = tempOut_nestedScope8.get();
this.cursor = tempRef_cursor8.argValue;
@@ -508,8 +508,8 @@ public final class RowWriter {
new Reference<RowCursor>(this.cursor);
Out<RowCursor> tempOut_nestedScope10 =
new Out<RowCursor>();
this.row.WriteTypedSet(tempRef_cursor10, scopeType, typeArg.typeArgs().clone(),
UpdateOptions.Upsert, tempOut_nestedScope10);
this.row.writeTypedSet(tempRef_cursor10, scopeType, typeArg.typeArgs().clone(),
UpdateOptions.Upsert);
nestedScope = tempOut_nestedScope10.get();
this.cursor = tempRef_cursor10.argValue;

View File

@@ -9,12 +9,18 @@ import com.azure.data.cosmos.serialization.hybridrow.SchemaId;
import com.azure.data.cosmos.serialization.hybridrow.schemas.Namespace;
import com.azure.data.cosmos.serialization.hybridrow.schemas.Schema;
import com.azure.data.cosmos.serialization.hybridrow.schemas.StorageKind;
import com.google.common.collect.ImmutableList;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
/**
@@ -42,15 +48,22 @@ public final class Layout {
private final SchemaId schemaId;
private final int size;
private final StringTokenizer tokenizer;
private final LayoutColumn[] topColumns;
private final ImmutableList<LayoutColumn> topColumns;
@SuppressWarnings("UnstableApiUsage")
public Layout(
@Nonnull final String name, @Nonnull final SchemaId schemaId, final int numBitmaskBytes,
final int minRequiredSize, @Nonnull final ArrayList<LayoutColumn> columns
) {
checkNotNull(name);
checkNotNull(schemaId);
checkNotNull(columns);
@Nonnull final String name,
@Nonnull final SchemaId schemaId,
final int numBitmaskBytes,
final int minRequiredSize,
@Nonnull final ArrayList<LayoutColumn> columns) {
checkNotNull(name, "expected non-null name");
checkNotNull(schemaId, "expected non-null schemaId");
checkNotNull(columns, "expected non-null columns");
checkArgument(numBitmaskBytes >= 0, "expected non-negative numBitmaskBytes, not %s", numBitmaskBytes);
checkArgument(minRequiredSize >= 0, "expected non-negative minRequiredSize", minRequiredSize);
this.name = name;
this.schemaId = schemaId;
@@ -60,7 +73,7 @@ public final class Layout {
this.pathMap = new HashMap<>(columns.size());
this.pathStringMap = new HashMap<>(columns.size());
final ArrayList<LayoutColumn> top = new ArrayList<>(columns.size());
ImmutableList.Builder<LayoutColumn> builder = ImmutableList.builderWithExpectedSize(columns.size());
int numFixed = 0;
int numVariable = 0;
@@ -77,13 +90,13 @@ public final class Layout {
}
if (column.parent() == null) {
top.add(column);
builder.add(column);
}
}
this.numFixed = numFixed;
this.numVariable = numVariable;
this.topColumns = top.toArray(new LayoutColumn[0]);
this.topColumns = builder.build();
}
/**
@@ -119,10 +132,12 @@ public final class Layout {
}
/**
* The set of top level columns defined in the layout (in left-to-right order).
* Top level columns defined by the current {@link Layout} in left-to-right order
*
* @return Top level columns defined by the current {@link Layout} in left-to-right order
*/
public ReadOnlySpan<LayoutColumn> columns() {
return this.topColumns.AsSpan();
public List<LayoutColumn> columns() {
return this.topColumns;
}
/**
@@ -186,18 +201,18 @@ public final class Layout {
StringBuilder sb = new StringBuilder();
sb.append("Layout:\n");
sb.append(String.format("\tCount: %1$s\n", this.topColumns.length));
sb.append(String.format("\tCount: %1$s\n", this.topColumns.size()));
sb.append(String.format("\tFixedSize: %1$s\n", this.size()));
for (LayoutColumn column : this.topColumns) {
if (column.type().isFixed()) {
if (column.type().isBoolean()) {
sb.append(String.format("\t%1$s: %2$s @ %3$s:%4$s:%5$s\n", column.fullPath(), column.type().name(), column.getOffset(), column.getNullBit(), column.getBooleanBit()));
sb.append(String.format("\t%1$s: %2$s @ %3$s:%4$s:%5$s\n", column.fullPath(), column.type().name(), column.offset(), column.nullBit(), column.booleanBit()));
} else {
sb.append(String.format("\t%1$s: %2$s @ %3$s\n", column.fullPath(), column.type().name(), column.getOffset()));
sb.append(String.format("\t%1$s: %2$s @ %3$s\n", column.fullPath(), column.type().name(), column.offset()));
}
} else {
sb.append(String.format("\t%1$s: %2$s[%4$s] @ %3$s\n", column.fullPath(), column.type().name(), column.getOffset(), column.getSize()));
sb.append(String.format("\t%1$s: %2$s[%4$s] @ %3$s\n", column.fullPath(), column.type().name(), column.offset(), column.size()));
}
}

View File

@@ -45,7 +45,7 @@ public final class LayoutArray extends LayoutIndexedScope {
return result;
}
b.WriteSparseArray(edit, this, options, value);
b.writeSparseArray(edit, this, options);
return Result.SUCCESS;
}
}

View File

@@ -117,7 +117,7 @@ public final class LayoutBinary extends LayoutType<byte[]> implements ILayoutSpa
return Result.NOT_FOUND;
}
int varOffset = b.get().ComputeVariableValueOffset(scope.get().layout(), scope.get().start(),
int varOffset = b.get().computeVariableValueOffset(scope.get().layout(), scope.get().start(),
col.getOffset());
value.setAndGet(b.get().readVariableBinary(varOffset));
return Result.SUCCESS;
@@ -255,7 +255,7 @@ public final class LayoutBinary extends LayoutType<byte[]> implements ILayoutSpa
}
boolean exists = b.get().readBit(scope.get().start(), col.getNullBit().clone());
int varOffset = b.get().ComputeVariableValueOffset(scope.get().layout(), scope.get().start(),
int varOffset = b.get().computeVariableValueOffset(scope.get().layout(), scope.get().start(),
col.getOffset());
int shift;
Out<Integer> tempOut_shift = new Out<Integer>();
@@ -283,7 +283,7 @@ public final class LayoutBinary extends LayoutType<byte[]> implements ILayoutSpa
}
boolean exists = b.get().readBit(scope.get().start(), col.getNullBit().clone());
int varOffset = b.get().ComputeVariableValueOffset(scope.get().layout(), scope.get().start(),
int varOffset = b.get().computeVariableValueOffset(scope.get().layout(), scope.get().start(),
col.getOffset());
int shift;
Out<Integer> tempOut_shift = new Out<Integer>();

View File

@@ -80,7 +80,7 @@ public final class LayoutNullable extends LayoutIndexedScope {
return result;
}
b.get().writeNullable(edit, this, typeArgs.clone(), options, hasValue, value.clone());
b.get().writeNullable(edit, this, typeArgs.clone(), options, hasValue);
return Result.SUCCESS;
}

View File

@@ -148,7 +148,7 @@ public abstract class LayoutType<T> implements ILayoutType {
boolean exists = b.readBit(scope.start(), column.nullBit());
if (exists) {
int varOffset = b.ComputeVariableValueOffset(scope.layout(), scope.start(), column.offset());
int varOffset = b.computeVariableValueOffset(scope.layout(), scope.start(), column.offset());
b.deleteVariable(varOffset, this.isVarint());
b.unsetBit(scope.start(), column.nullBit());
}

View File

@@ -92,7 +92,7 @@ public final class LayoutUtf8 extends LayoutType<String> implements ILayoutUtf8S
return Result.NOT_FOUND;
}
int varOffset = b.get().ComputeVariableValueOffset(scope.get().layout(), scope.get().start(),
int varOffset = b.get().computeVariableValueOffset(scope.get().layout(), scope.get().start(),
col.getOffset());
value.setAndGet(b.get().readVariableString(varOffset));
return Result.SUCCESS;
@@ -149,7 +149,7 @@ public final class LayoutUtf8 extends LayoutType<String> implements ILayoutUtf8S
return result;
}
b.get().WriteSparseString(edit, value, options);
b.get().writeSparseString(edit, value, options);
return Result.SUCCESS;
}
@@ -173,7 +173,7 @@ public final class LayoutUtf8 extends LayoutType<String> implements ILayoutUtf8S
}
boolean exists = b.get().readBit(scope.get().start(), col.getNullBit().clone());
int varOffset = b.get().ComputeVariableValueOffset(scope.get().layout(), scope.get().start(),
int varOffset = b.get().computeVariableValueOffset(scope.get().layout(), scope.get().start(),
col.getOffset());
int shift;
Out<Integer> tempOut_shift = new Out<Integer>();

View File

@@ -98,7 +98,7 @@ public final class LayoutVarInt extends LayoutType<Long> {
}
boolean exists = b.get().readBit(scope.get().start(), col.getNullBit().clone());
int varOffset = b.get().ComputeVariableValueOffset(scope.get().layout(), scope.get().start(),
int varOffset = b.get().computeVariableValueOffset(scope.get().layout(), scope.get().start(),
col.getOffset());
int shift;
Out<Integer> tempOut_shift = new Out<Integer>();

View File

@@ -115,7 +115,7 @@ public final class LayoutVarUInt extends LayoutType<Long> {
}
boolean exists = b.get().readBit(scope.get().start(), col.getNullBit().clone());
int varOffset = b.get().ComputeVariableValueOffset(scope.get().layout(), scope.get().start(),
int varOffset = b.get().computeVariableValueOffset(scope.get().layout(), scope.get().start(),
col.getOffset());
int shift;
Out<Integer> tempOut_shift = new Out<Integer>();

View File

@@ -54,7 +54,7 @@ public final class StringTokenizer {
* @param path The string to look up.
* @return {@code true} if successful, {@code false} otherwise.
*/
public Optional<StringToken> findToken(UtfAnyString path) {
public Optional<StringToken> tryFindToken(UtfAnyString path) {
if (path.isNull()) {
return Optional.empty();