Progressed on port from dotnet to java

This commit is contained in:
David Noble
2019-09-11 15:40:50 -07:00
parent 00c0bcd0bc
commit 76e62cbd99
40 changed files with 1462 additions and 1608 deletions

View File

@@ -1,37 +1,37 @@
// Copyright (c) Microsoft Corporation. All rights reserved. // Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. // Licensed under the MIT License.
package com.azure.data.cosmos.serialization.hybridrow.recordio; package com.azure.data.cosmos.serialization.hybridrow.recordio;
public final class Record { public final class Record {
public static Record empty() { public static Record empty() {
return new Record(0, 0); return new Record(0, 0);
} }
private int crc32; private int crc32;
private int length; 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 int crc32() { public int crc32() {
return this.crc32; return this.crc32;
} }
public Record crc32(int value) { public Record crc32(int value) {
this.crc32 = value; this.crc32 = value;
return this; return this;
} }
public int length() { public int length() {
return this.length; return this.length;
} }
public Record length(int value) { public Record length(int value) {
this.length = value; this.length = value;
return this; return this;
} }
} }

View File

@@ -1,78 +1,78 @@
// Copyright (c) Microsoft Corporation. All rights reserved. // Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. // Licensed under the MIT License.
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.serialization.hybridrow.HybridRowHeader; import com.azure.data.cosmos.serialization.hybridrow.HybridRowHeader;
import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion; import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion;
import com.azure.data.cosmos.serialization.hybridrow.ISpanResizer; import com.azure.data.cosmos.serialization.hybridrow.ISpanResizer;
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.layouts.Layout; 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 RECORD_LAYOUT = SystemSchema.layoutResolver.resolve(SystemSchema.RECORD_SCHEMA_ID); 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 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);
} }
//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 static Result FormatRecord(ReadOnlyMemory<byte> body, out RowBuffer row, //ORIGINAL LINE: public static Result FormatRecord(ReadOnlyMemory<byte> body, out RowBuffer row,
// ISpanResizer<byte> resizer = default) // ISpanResizer<byte> resizer = default)
//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:
public static Result FormatRecord(ReadOnlyMemory<Byte> body, Out<RowBuffer> row, public static Result FormatRecord(ReadOnlyMemory<Byte> body, Out<RowBuffer> row,
ISpanResizer<Byte> resizer) { ISpanResizer<Byte> resizer) {
//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.RECORD_LAYOUT.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.RECORD_LAYOUT, record.clone(), return RecordIOFormatter.FormatObject(resizer, estimatedSize, RecordIOFormatter.RECORD_LAYOUT, record.clone(),
RecordSerializer.Write, row.clone()); RecordSerializer.Write, row.clone());
} }
public static Result FormatSegment(Segment segment, Out<RowBuffer> row) { public static Result FormatSegment(Segment segment, Out<RowBuffer> row) {
return FormatSegment(segment, row, null); return FormatSegment(segment, row, null);
} }
//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 static Result FormatSegment(Segment segment, out RowBuffer row, ISpanResizer<byte> //ORIGINAL LINE: public static Result FormatSegment(Segment segment, out RowBuffer row, ISpanResizer<byte>
// resizer = default) // resizer = default)
//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:
public static Result FormatSegment(Segment segment, Out<RowBuffer> row, ISpanResizer<Byte> resizer) { public static Result FormatSegment(Segment segment, Out<RowBuffer> row, ISpanResizer<Byte> resizer) {
//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 = int estimatedSize =
HybridRowHeader.BYTES + RecordIOFormatter.SEGMENT_LAYOUT.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.SEGMENT_LAYOUT, return RecordIOFormatter.FormatObject(resizer, estimatedSize, RecordIOFormatter.SEGMENT_LAYOUT,
segment.clone(), SegmentSerializer.Write, row.clone()); segment.clone(), SegmentSerializer.Write, row.clone());
} }
//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: private static Result FormatObject<T>(ISpanResizer<byte> resizer, int initialCapacity, Layout //ORIGINAL LINE: private static Result FormatObject<T>(ISpanResizer<byte> resizer, int initialCapacity, Layout
// layout, T obj, RowWriter.WriterFunc<T> writer, out RowBuffer row) // layout, T obj, RowWriter.WriterFunc<T> writer, out RowBuffer row)
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);
return r; return r;
} }
return Result.SUCCESS; return Result.SUCCESS;
} }
} }

View File

@@ -1,353 +1,354 @@
// Copyright (c) Microsoft Corporation. All rights reserved. // Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. // Licensed under the MIT License.
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.Reference;
import com.azure.data.cosmos.serialization.hybridrow.HybridRowHeader; import com.azure.data.cosmos.serialization.hybridrow.HybridRowHeader;
import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion; import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion;
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.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.io.Segment;
import io.netty.buffer.ByteBuf; import com.azure.data.cosmos.serialization.hybridrow.layouts.SystemSchema;
import it.unimi.dsi.fastutil.bytes.Byte2ObjectMap; import io.netty.buffer.ByteBuf;
import it.unimi.dsi.fastutil.bytes.Byte2ObjectOpenHashMap; import it.unimi.dsi.fastutil.bytes.Byte2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.bytes.Byte2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import javax.annotation.Nonnull;
import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Preconditions.checkState;
public final class RecordIOParser {
public final class RecordIOParser {
private Record record;
private Segment segment; private Record record;
private State state = State.values()[0]; private Segment segment;
private State state = State.values()[0];
/**
* Processes one buffers worth of data possibly advancing the parser state /**
* * Processes one buffers worth of data possibly advancing the parser state
* @param buffer1 The buffer to consume *
* @param type Indicates the type of Hybrid Row produced in {@code record} * @param buffer1 The buffer to consume
* @param record If non-empty, then the body of the next record in the sequence * @param type Indicates the type of Hybrid Row produced in {@code record}
* @param need The smallest number of bytes needed to advanced the parser state further * @param record If non-empty, then the body of the next record in the sequence
* <p> * @param need The smallest number of bytes needed to advanced the parser state further
* It is recommended that this method not be called again until at least this number of bytes are * <p>
* available. * It is recommended that this method not be called again until at least this number of bytes are
* @param consumed The number of bytes consumed from the input buffer * available.
* <p> * @param consumed The number of bytes consumed from the input buffer
* This number may be less than the total buffer size if the parser moved to a new state. * <p>
* @return {@link Result#SUCCESS} if no error has occurred;, otherwise the {@link Result} of the last error * This number may be less than the total buffer size if the parser moved to a new state.
* encountered during parsing. * @return {@link Result#SUCCESS} if no error has occurred;, otherwise the {@link Result} of the last error
* <p> * encountered during parsing.
* > * <p>
*/ * >
@Nonnull */
public Result process( @Nonnull
@Nonnull final ByteBuf buffer, public Result process(
@Nonnull final Out<ProductionType> type, @Nonnull final ByteBuf buffer,
@Nonnull final Out<ByteBuf> record, @Nonnull final Out<ProductionType> type,
@Nonnull final Out<Integer> need, @Nonnull final Out<ByteBuf> record,
@Nonnull final Out<Integer> consumed) { @Nonnull final Out<Integer> need,
@Nonnull final Out<Integer> consumed) {
Result result = Result.FAILURE;
type.set(ProductionType.NONE); Result result = Result.FAILURE;
record.set(null); type.set(ProductionType.NONE);
record.set(null);
final int start = buffer.readerIndex();
final int start = buffer.readerIndex();
switch (this.state) {
switch (this.state) {
case STATE:
this.state = State.NEED_SEGMENT_LENGTH; case STATE:
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java: this.state = State.NEED_SEGMENT_LENGTH;
// goto case State.NeedSegmentLength; // TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
// goto case State.NeedSegmentLength;
case NEED_SEGMENT_LENGTH: {
case NEED_SEGMENT_LENGTH: {
final int minimalSegmentRowSize = HybridRowHeader.BYTES + RecordIOFormatter.SEGMENT_LAYOUT.size();
final int minimalSegmentRowSize = HybridRowHeader.BYTES + RecordIOFormatter.SEGMENT_LAYOUT.size();
if (buffer.readableBytes() < minimalSegmentRowSize) {
consumed.set(buffer.readerIndex() - start); if (buffer.readableBytes() < minimalSegmentRowSize) {
need.set(minimalSegmentRowSize); consumed.set(buffer.readerIndex() - start);
return Result.INSUFFICIENT_BUFFER; need.set(minimalSegmentRowSize);
} return Result.INSUFFICIENT_BUFFER;
}
ByteBuf span = buffer.slice(buffer.readerIndex(), minimalSegmentRowSize);
RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.layoutResolver); ByteBuf span = buffer.slice(buffer.readerIndex(), minimalSegmentRowSize);
Reference<RowBuffer> tempReference_row = RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.layoutResolver);
new Reference<RowBuffer>(row); Reference<RowBuffer> tempReference_row =
RowReader reader = new RowReader(tempReference_row); new Reference<RowBuffer>(row);
row = tempReference_row.get(); RowReader reader = new RowReader(tempReference_row);
Reference<RowReader> tempReference_reader = row = tempReference_row.get();
new Reference<RowReader>(reader); Reference<RowReader> tempReference_reader =
Out<Segment> tempOut_segment = new Reference<RowReader>(reader);
new Out<Segment>(); Out<Segment> tempOut_segment =
result = SegmentSerializer.read(tempReference_reader, tempOut_segment); new Out<Segment>();
this.segment = tempOut_segment.get(); result = SegmentSerializer.read(tempReference_reader, tempOut_segment);
reader = tempReference_reader.get(); this.segment = tempOut_segment.get();
if (result != Result.SUCCESS) { reader = tempReference_reader.get();
break; if (result != Result.SUCCESS) {
} break;
}
this.state = State.NEED_SEGMENT;
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java: this.state = State.NEED_SEGMENT;
goto case State.NEED_SEGMENT // TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
} goto case State.NEED_SEGMENT
}
case NEED_SEGMENT: {
if (buffer.Length < this.segment.length()) { case NEED_SEGMENT: {
need.set(this.segment.length()); if (buffer.Length < this.segment.length()) {
consumed.set(buffer.Length - buffer.Length); need.set(this.segment.length());
return Result.INSUFFICIENT_BUFFER; consumed.set(buffer.Length - buffer.Length);
} return Result.INSUFFICIENT_BUFFER;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: Span<byte> span = b.Span.Slice(0, this.segment.Length); //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
Span<Byte> span = buffer.Span.Slice(0, this.segment.length()); //ORIGINAL LINE: Span<byte> span = b.Span.Slice(0, this.segment.Length);
RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.layoutResolver); Span<Byte> span = buffer.Span.Slice(0, this.segment.length());
Reference<RowBuffer> tempReference_row2 = RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.layoutResolver);
new Reference<RowBuffer>(row); Reference<RowBuffer> tempReference_row2 =
RowReader reader = new RowReader(tempReference_row2); new Reference<RowBuffer>(row);
row = tempReference_row2.get(); RowReader reader = new RowReader(tempReference_row2);
Reference<RowReader> tempReference_reader2 = row = tempReference_row2.get();
new Reference<RowReader>(reader); Reference<RowReader> tempReference_reader2 =
Out<Segment> tempOut_segment2 new Reference<RowReader>(reader);
= new Out<Segment>(); Out<Segment> tempOut_segment2
result = SegmentSerializer.read(tempReference_reader2, tempOut_segment2); = new Out<Segment>();
this.segment = tempOut_segment2.get(); result = SegmentSerializer.read(tempReference_reader2, tempOut_segment2);
reader = tempReference_reader2.get(); this.segment = tempOut_segment2.get();
if (result != Result.SUCCESS) { reader = tempReference_reader2.get();
break; if (result != Result.SUCCESS) {
} break;
}
record.set(buffer.Slice(0, span.Length));
buffer = buffer.Slice(span.Length); record.set(buffer.Slice(0, span.Length));
need.set(0); buffer = buffer.Slice(span.Length);
this.state = State.NEED_HEADER; need.set(0);
consumed.set(buffer.Length - buffer.Length); this.state = State.NEED_HEADER;
type.set(ProductionType.SEGMENT); consumed.set(buffer.Length - buffer.Length);
return Result.SUCCESS; type.set(ProductionType.SEGMENT);
} return Result.SUCCESS;
}
case NEED_HEADER: {
if (buffer.Length < HybridRowHeader.BYTES) { case NEED_HEADER: {
need.set(HybridRowHeader.BYTES); if (buffer.Length < HybridRowHeader.BYTES) {
consumed.set(buffer.Length - buffer.Length); need.set(HybridRowHeader.BYTES);
return Result.INSUFFICIENT_BUFFER; consumed.set(buffer.Length - buffer.Length);
} return Result.INSUFFICIENT_BUFFER;
}
HybridRowHeader header;
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - HybridRowHeader header;
// these cannot be converted using the 'Out' helper class unless the method is within the code // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword -
// being modified: // these cannot be converted using the 'Out' helper class unless the method is within the code
MemoryMarshal.TryRead(buffer.Span, out header); // being modified:
if (header.Version != HybridRowVersion.V1) { MemoryMarshal.TryRead(buffer.Span, out header);
result = Result.INVALID_ROW; if (header.Version != HybridRowVersion.V1) {
break; result = Result.INVALID_ROW;
} break;
}
if (SchemaId.opEquals(header.SchemaId,
SystemSchema.SEGMENT_SCHEMA_ID)) { if (SchemaId.opEquals(header.SchemaId,
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java: SystemSchema.SEGMENT_SCHEMA_ID)) {
goto case State.NEED_SEGMENT // TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
} goto case State.NEED_SEGMENT
}
if (SchemaId.opEquals(header.SchemaId,
SystemSchema.RECORD_SCHEMA_ID)) { if (SchemaId.opEquals(header.SchemaId,
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java: SystemSchema.RECORD_SCHEMA_ID)) {
goto case State.NEED_RECORD // TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
} goto case State.NEED_RECORD
}
result = Result.INVALID_ROW;
break; result = Result.INVALID_ROW;
} break;
}
case NEED_RECORD: {
int minimalRecordRowSize = HybridRowHeader.BYTES + RecordIOFormatter.RECORD_LAYOUT.size(); case NEED_RECORD: {
if (buffer.Length < minimalRecordRowSize) { int minimalRecordRowSize = HybridRowHeader.BYTES + RecordIOFormatter.RECORD_LAYOUT.size();
need.set(minimalRecordRowSize); if (buffer.Length < minimalRecordRowSize) {
consumed.set(buffer.Length - buffer.Length); need.set(minimalRecordRowSize);
return Result.INSUFFICIENT_BUFFER; consumed.set(buffer.Length - buffer.Length);
} return Result.INSUFFICIENT_BUFFER;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: Span<byte> span = b.Span.Slice(0, minimalRecordRowSize); //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
Span<Byte> span = buffer.Span.Slice(0, minimalRecordRowSize); //ORIGINAL LINE: Span<byte> span = b.Span.Slice(0, minimalRecordRowSize);
RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.layoutResolver); Span<Byte> span = buffer.Span.Slice(0, minimalRecordRowSize);
Reference<RowBuffer> tempReference_row3 = RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.layoutResolver);
new Reference<RowBuffer>(row); Reference<RowBuffer> tempReference_row3 =
RowReader reader = new RowReader(tempReference_row3); new Reference<RowBuffer>(row);
row = tempReference_row3.get(); RowReader reader = new RowReader(tempReference_row3);
Reference<RowReader> tempReference_reader3 = new Reference<RowReader>(reader); row = tempReference_row3.get();
Out<Record> tempOut_record = new Out<Record>(); Reference<RowReader> tempReference_reader3 = new Reference<RowReader>(reader);
result = RecordSerializer.read(tempReference_reader3, tempOut_record); Out<Record> tempOut_record = new Out<Record>();
this.record = tempOut_record.get(); result = RecordSerializer.read(tempReference_reader3, tempOut_record);
reader = tempReference_reader3.get(); this.record = tempOut_record.get();
if (result != Result.SUCCESS) { reader = tempReference_reader3.get();
break; if (result != Result.SUCCESS) {
} break;
}
buffer = buffer.Slice(span.Length);
this.state = State.NEED_ROW; buffer = buffer.Slice(span.Length);
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java: this.state = State.NEED_ROW;
goto case State.NEED_ROW // TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
} goto case State.NEED_ROW
}
case NEED_ROW: {
if (buffer.Length < this.record.length()) { case NEED_ROW: {
need.set(this.record.length()); if (buffer.Length < this.record.length()) {
consumed.set(buffer.Length - buffer.Length); need.set(this.record.length());
return Result.INSUFFICIENT_BUFFER; consumed.set(buffer.Length - buffer.Length);
} return Result.INSUFFICIENT_BUFFER;
}
record.set(buffer.Slice(0, this.record.length()));
record.set(buffer.Slice(0, this.record.length()));
// Validate that the record has not been corrupted.
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: // Validate that the record has not been corrupted.
//ORIGINAL LINE: uint crc32 = Crc32.Update(0, record.Span); //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
int crc32 = Crc32.Update(0, record.get().Span); //ORIGINAL LINE: uint crc32 = Crc32.Update(0, record.Span);
if (crc32 != this.record.crc32()) { int crc32 = Crc32.Update(0, record.get().Span);
result = Result.INVALID_ROW; if (crc32 != this.record.crc32()) {
break; result = Result.INVALID_ROW;
} break;
}
buffer = buffer.Slice(this.record.length());
need.set(0); buffer = buffer.Slice(this.record.length());
this.state = State.NEED_HEADER; need.set(0);
consumed.set(buffer.Length - buffer.Length); this.state = State.NEED_HEADER;
type.set(ProductionType.RECORD); consumed.set(buffer.Length - buffer.Length);
return Result.SUCCESS; type.set(ProductionType.RECORD);
} return Result.SUCCESS;
} }
}
this.state = State.ERROR;
need.set(0); this.state = State.ERROR;
consumed.set(buffer.Length - buffer.Length); need.set(0);
return result; consumed.set(buffer.Length - buffer.Length);
} return result;
}
/**
* True if a valid segment has been parsed. /**
*/ * True if a valid segment has been parsed.
public boolean haveSegment() { */
return this.state.value() >= State.NEED_HEADER.value(); public boolean haveSegment() {
} return this.state.value() >= State.NEED_HEADER.value();
}
/**
* If a valid segment has been parsed then current active segment, otherwise undefined. /**
*/ * If a valid segment has been parsed then current active segment, otherwise undefined.
public Segment segment() { */
checkState(this.haveSegment()); public Segment segment() {
return this.segment; checkState(this.haveSegment());
} return this.segment;
}
/**
* Describes the type of Hybrid Rows produced by the parser. /**
*/ * Describes the type of Hybrid Rows produced by the parser.
public enum ProductionType { */
/** public enum ProductionType {
* 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 BYTES = Integer.BYTES;
public static final int BYTES = Integer.BYTES;
private static Int2ObjectMap<ProductionType> mappings;
private int value; private static Int2ObjectMap<ProductionType> mappings;
private int value;
ProductionType(int value) {
this.value = value; ProductionType(int value) {
mappings().put(value, this); this.value = value;
} mappings().put(value, this);
}
public int value() {
return this.value; public int value() {
} return this.value;
}
public static ProductionType from(int value) {
return mappings().get(value); public static ProductionType from(int value) {
} return mappings().get(value);
}
private static Int2ObjectMap<ProductionType> mappings() {
if (mappings == null) { private static Int2ObjectMap<ProductionType> mappings() {
synchronized (ProductionType.class) { if (mappings == null) {
if (mappings == null) { synchronized (ProductionType.class) {
mappings = new Int2ObjectOpenHashMap<>(); if (mappings == null) {
} mappings = new Int2ObjectOpenHashMap<>();
} }
} }
return mappings; }
} return mappings;
} }
}
/**
* The states for the internal state machine. /**
* Note: numerical ordering of these states matters. * The states for the internal state machine.
*/ * Note: numerical ordering of these states matters.
private enum State { */
STATE( private enum State {
(byte) 0, "Start: no buffers have yet been provided to the parser"), STATE(
ERROR( (byte) 0, "Start: no buffers have yet been provided to the parser"),
(byte) 1, "Unrecoverable parse error encountered"), ERROR(
NEED_SEGMENT_LENGTH( (byte) 1, "Unrecoverable parse error encountered"),
(byte) 2, "Parsing segment header length"), NEED_SEGMENT_LENGTH(
NEED_SEGMENT( (byte) 2, "Parsing segment header length"),
(byte) 3, "Parsing segment header"), NEED_SEGMENT(
NEED_HEADER( (byte) 3, "Parsing segment header"),
(byte) 4, "Parsing HybridRow header"), NEED_HEADER(
NEED_RECORD( (byte) 4, "Parsing HybridRow header"),
(byte) 5, "Parsing record header"), NEED_RECORD(
NEED_ROW( (byte) 5, "Parsing record header"),
(byte) 6, "Parsing row body"); NEED_ROW(
(byte) 6, "Parsing row body");
public static final int BYTES = Byte.SIZE;
public static final int BYTES = Byte.SIZE;
private static Byte2ObjectMap<State> mappings;
private final String description; private static Byte2ObjectMap<State> mappings;
private final byte value; private final String description;
private final byte value;
State(byte value, String description) {
this.description = description; State(byte value, String description) {
this.value = value; this.description = description;
mappings().put(value, this); this.value = value;
} mappings().put(value, this);
}
public String description() {
return this.description; public String description() {
} return this.description;
}
public byte value() {
return this.value; public byte value() {
} return this.value;
}
public static State from(byte value) {
return mappings().get(value); public static State from(byte value) {
} return mappings().get(value);
}
private static Byte2ObjectMap<State> mappings() {
if (mappings == null) { private static Byte2ObjectMap<State> mappings() {
synchronized (State.class) { if (mappings == null) {
if (mappings == null) { synchronized (State.class) {
mappings = new Byte2ObjectOpenHashMap<>(); if (mappings == null) {
} mappings = new Byte2ObjectOpenHashMap<>();
} }
} }
return mappings; }
} return mappings;
} }
}
} }

View File

@@ -1,368 +1,368 @@
// Copyright (c) Microsoft Corporation. All rights reserved. // Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. // Licensed under the MIT License.
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.serialization.hybridrow.MemorySpanResizer; import com.azure.data.cosmos.serialization.hybridrow.MemorySpanResizer;
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 java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
public final class RecordIOStream { public final class RecordIOStream {
/** /**
* A function that produces RecordIO record bodies. * A function that produces RecordIO record bodies.
* <p> * <p>
* Record bodies are returned as memory blocks. It is expected that each block is a * Record bodies are returned as memory blocks. It is expected that each block is a
* HybridRow, but any binary data is allowed. * HybridRow, but any binary data is allowed.
* *
* @param index The 0-based index of the record within the segment to be produced. * @param index The 0-based index of the record within the segment to be produced.
* @return A tuple with: Success if the body was produced without error, the error code otherwise. * @return A tuple with: Success if the body was produced without error, the error code otherwise.
* And, the byte sequence of the record body's row buffer. * And, the byte sequence of the record body's row buffer.
*/ */
public delegate ValueTask public delegate ValueTask
ProduceFuncAsync(long index);<(Result,ReadOnlyMemory<Byte>)> ProduceFuncAsync(long index);<(Result,ReadOnlyMemory<Byte>)>
/** /**
* Reads an entire RecordIO stream. * Reads an entire RecordIO stream.
* *
* @param stm The stream to read from. * @param stm The stream to read from.
* @param visitRecord A (required) delegate that is called once for each record. * @param visitRecord A (required) delegate that is called once for each record.
* <p> * <p>
* <paramref name="visitRecord" /> is passed a {@link Memory{T}} of the byte sequence * <paramref name="visitRecord" /> is passed a {@link Memory{T}} of the byte sequence
* of the * of the
* record body's row buffer. * record body's row buffer.
* </p> * </p>
* <p>If <paramref name="visitRecord" /> returns an error then the sequence is aborted.</p> * <p>If <paramref name="visitRecord" /> returns an error then the sequence is aborted.</p>
* @param visitSegment An (optional) delegate that is called once for each segment header. * @param visitSegment An (optional) delegate that is called once for each segment header.
* <p> * <p>
* If <paramref name="visitSegment" /> is not provided then segment headers are parsed but * If <paramref name="visitSegment" /> is not provided then segment headers are parsed but
* skipped * skipped
* over. * over.
* </p> * </p>
* <p> * <p>
* <paramref name="visitSegment" /> is passed a {@link Memory{T}} of the byte sequence of * <paramref name="visitSegment" /> is passed a {@link Memory{T}} of the byte sequence of
* the segment header's row buffer. * the segment header's row buffer.
* </p> * </p>
* <p>If <paramref name="visitSegment" /> returns an error then the sequence is aborted.</p> * <p>If <paramref name="visitSegment" /> returns an error then the sequence is aborted.</p>
* @param resizer Optional memory resizer. * @param resizer Optional memory resizer.
* @return Success if the stream is parsed without error, the error code otherwise. * @return Success if the stream is parsed without error, the error code otherwise.
*/ */
public static Task<Result> ReadRecordIOAsync(Stream stm, Func<Memory<Byte>, Result> visitRecord, public static Task<Result> ReadRecordIOAsync(Stream stm, Func<Memory<Byte>, Result> visitRecord,
Func<Memory<Byte>, Result> visitSegment) { Func<Memory<Byte>, Result> visitSegment) {
return ReadRecordIOAsync(stm, visitRecord, visitSegment, null); return ReadRecordIOAsync(stm, visitRecord, visitSegment, null);
} }
public static Task<Result> ReadRecordIOAsync(Stream stm, Func<Memory<Byte>, Result> visitRecord) { public static Task<Result> ReadRecordIOAsync(Stream stm, Func<Memory<Byte>, Result> visitRecord) {
return ReadRecordIOAsync(stm, visitRecord, null, null); return ReadRecordIOAsync(stm, visitRecord, null, null);
} }
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword: // TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
//ORIGINAL LINE: public static async Task<Result> ReadRecordIOAsync(this Stream stm, Func<Memory<byte>, Result> //ORIGINAL LINE: public static async Task<Result> ReadRecordIOAsync(this Stream stm, Func<Memory<byte>, Result>
// visitRecord, Func<Memory<byte>, Result> visitSegment = default, MemorySpanResizer<byte> resizer = default) // visitRecord, Func<Memory<byte>, Result> visitSegment = default, MemorySpanResizer<byte> resizer = default)
//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:
//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:
public static Task<Result> ReadRecordIOAsync(InputStream stm, public static Task<Result> ReadRecordIOAsync(InputStream stm,
tangible.Func1Param<Memory<Byte>, Result> visitRecord, tangible.Func1Param<Memory<Byte>, Result> visitRecord,
tangible.Func1Param<Memory<Byte>, Result> visitSegment, tangible.Func1Param<Memory<Byte>, Result> visitSegment,
MemorySpanResizer<Byte> resizer) { MemorySpanResizer<Byte> resizer) {
checkArgument(stm != null); checkArgument(stm != null);
checkArgument(visitRecord != null); checkArgument(visitRecord != null);
// Create a reusable, resizable buffer if the caller didn't provide one. // Create a reusable, resizable buffer if the caller didn't provide one.
//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 : new MemorySpanResizer<byte>(); //ORIGINAL LINE: resizer = resizer != null ? resizer : new MemorySpanResizer<byte>();
resizer = resizer != null ? resizer : new MemorySpanResizer<Byte>(); resizer = resizer != null ? resizer : new MemorySpanResizer<Byte>();
RecordIOParser parser = null; RecordIOParser parser = null;
int need = 0; int need = 0;
//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: Memory<byte> active = resizer.Memory; //ORIGINAL LINE: Memory<byte> active = resizer.Memory;
Memory<Byte> active = resizer.getMemory(); Memory<Byte> active = resizer.getMemory();
//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: Memory<byte> avail = default; //ORIGINAL LINE: Memory<byte> avail = default;
Memory<Byte> avail = null; Memory<Byte> avail = null;
while (true) { while (true) {
checkState(avail.Length < active.Length); checkState(avail.Length < active.Length);
checkState(active.Length > 0); checkState(active.Length > 0);
checkState(active.Length >= need); checkState(active.Length >= need);
// TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java: // TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java:
int read = await stm.ReadAsync(active.Slice(avail.Length)); int read = await stm.ReadAsync(active.Slice(avail.Length));
if (read == 0) { if (read == 0) {
break; break;
} }
avail = active.Slice(0, avail.Length + read); avail = active.Slice(0, avail.Length + read);
// If there isn't enough data to move the parser forward then just read again. // If there isn't enough data to move the parser forward then just read again.
if (avail.Length < need) { if (avail.Length < need) {
continue; continue;
} }
// Process the available data until no more forward progress is possible. // Process the available data until no more forward progress is possible.
while (avail.Length > 0) { while (avail.Length > 0) {
// Loop around processing available data until we don't have anymore // Loop around processing available data until we don't have anymore
RecordIOParser.ProductionType prodType; RecordIOParser.ProductionType prodType;
Out<RecordIOParser.ProductionType> tempOut_prodType = new Out<RecordIOParser.ProductionType>(); Out<RecordIOParser.ProductionType> tempOut_prodType = new Out<RecordIOParser.ProductionType>();
Memory<Byte> record; Memory<Byte> record;
Out<Memory<Byte>> tempOut_record = new Out<Memory<Byte>>(); Out<Memory<Byte>> tempOut_record = new Out<Memory<Byte>>();
Out<Integer> tempOut_need = new Out<Integer>(); Out<Integer> tempOut_need = new Out<Integer>();
int consumed; int consumed;
Out<Integer> tempOut_consumed = new Out<Integer>(); Out<Integer> tempOut_consumed = new Out<Integer>();
//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();
prodType = tempOut_prodType.get(); prodType = tempOut_prodType.get();
if ((r != Result.SUCCESS) && (r != Result.INSUFFICIENT_BUFFER)) { if ((r != Result.SUCCESS) && (r != Result.INSUFFICIENT_BUFFER)) {
return r; return r;
} }
active = active.Slice(consumed); active = active.Slice(consumed);
avail = avail.Slice(consumed); avail = avail.Slice(consumed);
if (avail.IsEmpty) { if (avail.IsEmpty) {
active = resizer.getMemory(); active = resizer.getMemory();
} }
// If there wasn't enough data to move the parser forward then get more data. // If there wasn't enough data to move the parser forward then get more data.
if (r == Result.INSUFFICIENT_BUFFER) { if (r == Result.INSUFFICIENT_BUFFER) {
if (need > active.Length) { if (need > active.Length) {
resizer.Resize(need, avail.Span); resizer.Resize(need, avail.Span);
active = resizer.getMemory(); active = resizer.getMemory();
avail = resizer.getMemory().Slice(0, avail.Length); avail = resizer.getMemory().Slice(0, avail.Length);
} }
break; break;
} }
// 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;
if (r != Result.SUCCESS) { if (r != Result.SUCCESS) {
return r; return r;
} }
} }
// 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);
if (r != Result.SUCCESS) { if (r != Result.SUCCESS) {
return r; return r;
} }
} }
} }
} }
// Make sure we processed all of the available data. // Make sure we processed all of the available data.
checkState(avail.Length == 0); checkState(avail.Length == 0);
return Result.SUCCESS; return Result.SUCCESS;
} }
/** /**
* Writes a RecordIO segment into a stream. * Writes a RecordIO segment into a stream.
* *
* @param stm The stream to write to. * @param stm The stream to write to.
* @param segment The segment header to write. * @param segment The segment header to write.
* @param produce A function to produces the record bodies for the segment. * @param produce A function to produces the record bodies for the segment.
* <p> * <p>
* The <paramref name="produce" /> function is called until either an error is encountered or it * The <paramref name="produce" /> function is called until either an error is encountered or it
* produces an empty body. An empty body terminates the segment. * produces an empty body. An empty body terminates the segment.
* </p> * </p>
* <p>If <paramref name="produce" /> returns an error then the sequence is aborted.</p> * <p>If <paramref name="produce" /> returns an error then the sequence is aborted.</p>
* @param resizer Optional memory resizer for RecordIO metadata row buffers. * @param resizer Optional memory resizer for RecordIO metadata row buffers.
* <p> * <p>
* <em>Note:</em> This should <em>NOT</em> be the same resizer used to process any rows as both * <em>Note:</em> This should <em>NOT</em> be the same resizer used to process any rows as both
* blocks of memory are used concurrently. * blocks of memory are used concurrently.
* </p> * </p>
* @return Success if the stream is written without error, the error code otherwise. * @return Success if the stream is written without error, the error code otherwise.
*/ */
public static Task<Result> WriteRecordIOAsync(Stream stm, Segment segment, ProduceFunc produce) { public static Task<Result> WriteRecordIOAsync(Stream stm, Segment segment, ProduceFunc produce) {
return WriteRecordIOAsync(stm, segment, produce, null); return WriteRecordIOAsync(stm, segment, produce, null);
} }
//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 static Task<Result> WriteRecordIOAsync(this Stream stm, Segment segment, ProduceFunc //ORIGINAL LINE: public static Task<Result> WriteRecordIOAsync(this Stream stm, Segment segment, ProduceFunc
// produce, MemorySpanResizer<byte> resizer = default) // produce, MemorySpanResizer<byte> resizer = default)
// TODO: C# TO JAVA CONVERTER: C# to Java Converter cannot determine whether this System.IO.Stream is input or // TODO: C# TO JAVA CONVERTER: C# to Java Converter cannot determine whether this System.IO.Stream is input or
// output: // output:
//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:
public static Task<Result> WriteRecordIOAsync(Stream stm, Segment segment, ProduceFunc produce, public static Task<Result> WriteRecordIOAsync(Stream stm, Segment segment, ProduceFunc produce,
MemorySpanResizer<Byte> resizer) { MemorySpanResizer<Byte> resizer) {
return RecordIOStream.WriteRecordIOAsync(stm, return RecordIOStream.WriteRecordIOAsync(stm,
segment.clone(), index -> segment.clone(), index ->
{ {
ReadOnlyMemory<Byte> buffer; ReadOnlyMemory<Byte> buffer;
Out<ReadOnlyMemory<Byte>> tempOut_buffer = new Out<ReadOnlyMemory<Byte>>(); Out<ReadOnlyMemory<Byte>> tempOut_buffer = new Out<ReadOnlyMemory<Byte>>();
buffer = tempOut_buffer.get(); buffer = tempOut_buffer.get();
return new ValueTask<(Result, ReadOnlyMemory < Byte >) > ((r,buffer)) return new ValueTask<(Result, ReadOnlyMemory < Byte >) > ((r,buffer))
}, resizer); }, resizer);
} }
/** /**
* Writes a RecordIO segment into a stream. * Writes a RecordIO segment into a stream.
* *
* @param stm The stream to write to. * @param stm The stream to write to.
* @param segment The segment header to write. * @param segment The segment header to write.
* @param produce A function to produces the record bodies for the segment. * @param produce A function to produces the record bodies for the segment.
* <p> * <p>
* The <paramref name="produce" /> function is called until either an error is encountered or it * The <paramref name="produce" /> function is called until either an error is encountered or it
* produces an empty body. An empty body terminates the segment. * produces an empty body. An empty body terminates the segment.
* </p> * </p>
* <p>If <paramref name="produce" /> returns an error then the sequence is aborted.</p> * <p>If <paramref name="produce" /> returns an error then the sequence is aborted.</p>
* @param resizer Optional memory resizer for RecordIO metadata row buffers. * @param resizer Optional memory resizer for RecordIO metadata row buffers.
* <p> * <p>
* <em>Note:</em> This should <em>NOT</em> be the same resizer used to process any rows as both * <em>Note:</em> This should <em>NOT</em> be the same resizer used to process any rows as both
* blocks of memory are used concurrently. * blocks of memory are used concurrently.
* </p> * </p>
* @return Success if the stream is written without error, the error code otherwise. * @return Success if the stream is written without error, the error code otherwise.
*/ */
public static Task<Result> WriteRecordIOAsync(Stream stm, Segment segment, ProduceFuncAsync produce) { public static Task<Result> WriteRecordIOAsync(Stream stm, Segment segment, ProduceFuncAsync produce) {
return WriteRecordIOAsync(stm, segment, produce, null); return WriteRecordIOAsync(stm, segment, produce, null);
} }
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword: // TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
//ORIGINAL LINE: public static async Task<Result> WriteRecordIOAsync(this Stream stm, Segment segment, //ORIGINAL LINE: public static async Task<Result> WriteRecordIOAsync(this Stream stm, Segment segment,
// ProduceFuncAsync produce, MemorySpanResizer<byte> resizer = default) // ProduceFuncAsync produce, MemorySpanResizer<byte> resizer = default)
//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:
//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:
public static Task<Result> WriteRecordIOAsync(OutputStream stm, Segment segment, ProduceFuncAsync produce, public static Task<Result> WriteRecordIOAsync(OutputStream stm, Segment segment, ProduceFuncAsync produce,
MemorySpanResizer<Byte> resizer) { MemorySpanResizer<Byte> resizer) {
// Create a reusable, resizable buffer if the caller didn't provide one. // Create a reusable, resizable buffer if the caller didn't provide one.
//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 : new MemorySpanResizer<byte>(); //ORIGINAL LINE: resizer = resizer != null ? resizer : new MemorySpanResizer<byte>();
resizer = resizer != null ? resizer : new MemorySpanResizer<Byte>(); resizer = resizer != null ? resizer : new MemorySpanResizer<Byte>();
// Write a RecordIO stream. // Write a RecordIO stream.
Memory<Byte> metadata; Memory<Byte> metadata;
Out<Memory<Byte>> tempOut_metadata = new Out<Memory<Byte>>(); Out<Memory<Byte>> tempOut_metadata = new Out<Memory<Byte>>();
//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 = RecordIOStream.FormatSegment(segment, resizer, out Memory<byte> metadata); //ORIGINAL LINE: Result r = RecordIOStream.FormatSegment(segment, resizer, out Memory<byte> metadata);
Result r = RecordIOStream.FormatSegment(segment.clone(), resizer, tempOut_metadata); Result r = RecordIOStream.FormatSegment(segment.clone(), resizer, tempOut_metadata);
metadata = tempOut_metadata.get(); metadata = tempOut_metadata.get();
if (r != Result.SUCCESS) { if (r != Result.SUCCESS) {
return r; return r;
} }
// TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java: // TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java:
await stm.WriteAsync(metadata); await stm.WriteAsync(metadata);
long index = 0; long index = 0;
while (true) { while (true) {
//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: ReadOnlyMemory<byte> body; //ORIGINAL LINE: ReadOnlyMemory<byte> body;
ReadOnlyMemory<Byte> body; ReadOnlyMemory<Byte> body;
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to the C# deconstruction assignments: // TODO: C# TO JAVA CONVERTER: Java has no equivalent to the C# deconstruction assignments:
(r, body) =await produce (index++); (r, body) =await produce (index++);
if (r != Result.SUCCESS) { if (r != Result.SUCCESS) {
return r; return r;
} }
if (body.IsEmpty) { if (body.IsEmpty) {
break; break;
} }
Out<Memory<Byte>> tempOut_metadata2 = new Out<Memory<Byte>>(); Out<Memory<Byte>> tempOut_metadata2 = new Out<Memory<Byte>>();
//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: r = RecordIOStream.FormatRow(body, resizer, out metadata); //ORIGINAL LINE: r = RecordIOStream.FormatRow(body, resizer, out metadata);
r = RecordIOStream.FormatRow(body, resizer, tempOut_metadata2); r = RecordIOStream.FormatRow(body, resizer, tempOut_metadata2);
metadata = tempOut_metadata2.get(); metadata = tempOut_metadata2.get();
if (r != Result.SUCCESS) { if (r != Result.SUCCESS) {
return r; return r;
} }
// Metadata and Body memory blocks should not overlap since they are both in // Metadata and Body memory blocks should not overlap since they are both in
// play at the same time. If they do this usually means that the same resizer // play at the same time. If they do this usually means that the same resizer
// was incorrectly used for both. Check the resizer parameter passed to // was incorrectly used for both. Check the resizer parameter passed to
// WriteRecordIOAsync for metadata. // WriteRecordIOAsync for metadata.
checkState(!metadata.Span.Overlaps(body.Span)); checkState(!metadata.Span.Overlaps(body.Span));
// TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java: // TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java:
await stm.WriteAsync(metadata); await stm.WriteAsync(metadata);
// TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java: // TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java:
await stm.WriteAsync(body); await stm.WriteAsync(body);
} }
return Result.SUCCESS; return Result.SUCCESS;
} }
/** /**
* Compute and format a record header for the given record body. * Compute and format a record header for the given record body.
* *
* @param body The body whose record header should be formatted. * @param body The body whose record header should be formatted.
* @param resizer The resizer to use in allocating a buffer for the record header. * @param resizer The resizer to use in allocating a buffer for the record header.
* @param block The byte sequence of the written row buffer. * @param block The byte sequence of the written row buffer.
* @return Success if the write completes without error, the error code otherwise. * @return Success if the write completes without error, the error code otherwise.
*/ */
//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: private static Result FormatRow(ReadOnlyMemory<byte> body, MemorySpanResizer<byte> resizer, out Memory<byte> block) //ORIGINAL LINE: private static Result FormatRow(ReadOnlyMemory<byte> body, MemorySpanResizer<byte> resizer, out Memory<byte> block)
private static Result FormatRow(ReadOnlyMemory<Byte> body, MemorySpanResizer<Byte> resizer, Out<Memory<Byte>> block) { private static Result FormatRow(ReadOnlyMemory<Byte> body, MemorySpanResizer<Byte> resizer, Out<Memory<Byte>> block) {
RowBuffer row; RowBuffer row;
Out<RowBuffer> tempOut_row = new Out<RowBuffer>(); Out<RowBuffer> tempOut_row = new Out<RowBuffer>();
Result r = RecordIOFormatter.FormatRecord(body, tempOut_row, resizer); Result r = RecordIOFormatter.FormatRecord(body, tempOut_row, resizer);
row = tempOut_row.get(); row = tempOut_row.get();
if (r != Result.SUCCESS) { if (r != Result.SUCCESS) {
block.setAndGet(null); block.setAndGet(null);
return r; return r;
} }
block.setAndGet(resizer.getMemory().Slice(0, row.Length)); block.setAndGet(resizer.getMemory().Slice(0, row.Length));
return Result.SUCCESS; return Result.SUCCESS;
} }
/** /**
* Format a segment. * Format a segment.
* *
* @param segment The segment to format. * @param segment The segment to format.
* @param resizer The resizer to use in allocating a buffer for the segment. * @param resizer The resizer to use in allocating a buffer for the segment.
* @param block The byte sequence of the written row buffer. * @param block The byte sequence of the written row buffer.
* @return Success if the write completes without error, the error code otherwise. * @return Success if the write completes without error, the error code otherwise.
*/ */
//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: private static Result FormatSegment(Segment segment, MemorySpanResizer<byte> resizer, out //ORIGINAL LINE: private static Result FormatSegment(Segment segment, MemorySpanResizer<byte> resizer, out
// Memory<byte> block) // Memory<byte> block)
private static Result FormatSegment(Segment segment, MemorySpanResizer<Byte> resizer, private static Result FormatSegment(Segment segment, MemorySpanResizer<Byte> resizer,
Out<Memory<Byte>> block) { Out<Memory<Byte>> block) {
RowBuffer row; RowBuffer row;
Out<RowBuffer> tempOut_row = Out<RowBuffer> tempOut_row =
new Out<RowBuffer>(); new Out<RowBuffer>();
Result r = RecordIOFormatter.FormatSegment(segment.clone(), tempOut_row, resizer); Result r = RecordIOFormatter.FormatSegment(segment.clone(), tempOut_row, resizer);
row = tempOut_row.get(); row = tempOut_row.get();
if (r != Result.SUCCESS) { if (r != Result.SUCCESS) {
block.setAndGet(null); block.setAndGet(null);
return r; return r;
} }
block.setAndGet(resizer.getMemory().Slice(0, row.Length)); block.setAndGet(resizer.getMemory().Slice(0, row.Length));
return Result.SUCCESS; return Result.SUCCESS;
} }
/** /**
* A function that produces RecordIO record bodies. * A function that produces RecordIO record bodies.
* <p> * <p>
* Record bodies are returned as memory blocks. It is expected that each block is a * Record bodies are returned as memory blocks. It is expected that each block is a
* HybridRow, but any binary data is allowed. * HybridRow, but any binary data is allowed.
* *
* @param index The 0-based index of the record within the segment to be produced. * @param index The 0-based index of the record within the segment to be produced.
* @param buffer The byte sequence of the record body's row buffer. * @param buffer The byte sequence of the record body's row buffer.
* @return Success if the body was produced without error, the error code otherwise. * @return Success if the body was produced without error, the error code otherwise.
*/ */
@FunctionalInterface @FunctionalInterface
public interface ProduceFunc { public interface ProduceFunc {
Result invoke(long index, Out<ReadOnlyMemory<Byte>> buffer); Result invoke(long index, Out<ReadOnlyMemory<Byte>> buffer);
} }
} }

View File

@@ -1,68 +1,68 @@
// Copyright (c) Microsoft Corporation. All rights reserved. // Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. // Licensed under the MIT License.
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.UtfAnyString; 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.RowReader;
import com.azure.data.cosmos.serialization.hybridrow.io.RowWriter; import com.azure.data.cosmos.serialization.hybridrow.io.RowWriter;
import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument; import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
public final class RecordSerializer { public final class RecordSerializer {
@Nonnull @Nonnull
public static Result read(RowReader reader, Out<Record> record) { public static Result read(RowReader reader, Out<Record> record) {
Out<Integer> value = new Out<>(); Out<Integer> value = new Out<>();
record.set(Record.empty()); record.set(Record.empty());
while (reader.read()) { while (reader.read()) {
String path = reader.path().toUtf16(); String path = reader.path().toUtf16();
checkState(path != null); checkState(path != null);
Result result; Result result;
// TODO: use Path tokens here // TODO: use Path tokens here
switch (path) { switch (path) {
case "length": case "length":
result = reader.readInt32(value); result = reader.readInt32(value);
record.get().length(value.get()); record.get().length(value.get());
if (result != Result.SUCCESS) { if (result != Result.SUCCESS) {
return result; return result;
} }
break; break;
case "crc32": case "crc32":
result = reader.readInt32(value); result = reader.readInt32(value);
record.get().crc32(value.get()); record.get().crc32(value.get());
if (result != Result.SUCCESS) { if (result != Result.SUCCESS) {
return result; return result;
} }
break; break;
} }
} }
return Result.SUCCESS; return Result.SUCCESS;
} }
@Nonnull @Nonnull
public static Result write(RowWriter writer, TypeArgument typeArg, Record record) { public static Result write(RowWriter writer, TypeArgument typeArg, Record record) {
Result result = writer.writeInt32(new UtfAnyString("length"), record.length()); Result result = writer.writeInt32(new UtfAnyString("length"), record.length());
if (result != Result.SUCCESS) { if (result != Result.SUCCESS) {
return result; return result;
} }
return writer.writeUInt32(new UtfAnyString("crc32"), record.crc32()); return writer.writeUInt32(new UtfAnyString("crc32"), record.crc32());
} }
} }

View File

@@ -1,120 +1,123 @@
// Copyright (c) Microsoft Corporation. All rights reserved. // Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. // Licensed under the MIT License.
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.Utf8String; 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.HybridRowVersion; import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion;
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.io.RowReader; 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.io.RowWriter;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutResolver; import com.azure.data.cosmos.serialization.hybridrow.io.Segment;
import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutResolver;
import io.netty.buffer.ByteBuf; import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument;
import io.netty.buffer.ByteBuf;
import static com.google.common.base.Preconditions.checkState;
import java.util.Objects;
public final class SegmentSerializer {
import static com.google.common.base.Preconditions.checkState;
private static final UtfAnyString COMMENT = new UtfAnyString("comment");
private static final UtfAnyString LENGTH = new UtfAnyString("length"); public final class SegmentSerializer {
private static final UtfAnyString SDL = new UtfAnyString("sdl");
private static final UtfAnyString COMMENT = new UtfAnyString("comment");
public static Result read(ByteBuf buffer, LayoutResolver resolver, Out<Segment> segment) { private static final UtfAnyString LENGTH = new UtfAnyString("length");
RowReader reader = new RowReader(new RowBuffer(buffer, HybridRowVersion.V1, resolver)); private static final UtfAnyString SDL = new UtfAnyString("sdl");
return SegmentSerializer.read(reader, segment);
} public static Result read(ByteBuf buffer, LayoutResolver resolver, Out<Segment> segment) {
RowReader reader = new RowReader(new RowBuffer(buffer, HybridRowVersion.V1, resolver));
public static Result read(RowReader reader, Out<Segment> segment) { return SegmentSerializer.read(reader, segment);
}
segment.set(new Segment(null, null));
public static Result read(RowReader reader, Out<Segment> segment) {
final Out<Utf8String> comment = new Out<>();
final Out<Integer> length = new Out<>(); segment.set(new Segment(null, null));
final Out<Utf8String> sdl = new Out<>();
final Out<String> comment = new Out<>();
while (reader.read()) { final Out<Integer> length = new Out<>();
final Out<String> sdl = new Out<>();
// TODO: Use Path tokens here.
while (reader.read()) {
switch (reader.path().toString()) {
// TODO: Use Path tokens here.
case "length": {
switch (Objects.requireNonNull(reader.path().toUtf16())) {
Result result = reader.readInt32(length);
segment.get().length(length.get()); case "length": {
if (result != Result.SUCCESS) { Result result = reader.readInt32(length);
return result; segment.get().length(length.get());
}
if (result != Result.SUCCESS) {
if (reader.length() < segment.get().length()) { return result;
// RowBuffer isn't big enough to contain the rest of the header so just return the length }
return Result.SUCCESS;
} if (reader.length() < segment.get().length()) {
// RowBuffer isn't big enough to contain the rest of the header so just return the length
break; return Result.SUCCESS;
} }
case "comment": {
break;
Result result = reader.readString(comment); }
segment.get().comment(comment.get().toUtf16()); case "comment": {
if (result != Result.SUCCESS) { Result result = reader.readString(comment);
return result; segment.get().comment(comment.get());
}
if (result != Result.SUCCESS) {
break; return result;
} }
case "sdl": {
break;
Result result = reader.readString(sdl); }
segment.get().sdl(sdl.get().toUtf16()); case "sdl": {
if (result != Result.SUCCESS) { Result result = reader.readString(sdl);
return result; segment.get().sdl(sdl.get());
}
if (result != Result.SUCCESS) {
break; return result;
} }
}
} break;
}
return Result.SUCCESS; }
} }
public static Result write(RowWriter writer, TypeArgument typeArg, Segment segment) { return Result.SUCCESS;
}
Result result;
public static Result write(RowWriter writer, TypeArgument typeArg, Segment segment) {
if (segment.comment() != null) {
result = writer.writeString(COMMENT, segment.comment()); Result result;
if (result != Result.SUCCESS) {
return result; if (segment.comment() != null) {
} result = writer.writeString(COMMENT, segment.comment());
} if (result != Result.SUCCESS) {
return result;
if (segment.sdl() != null) { }
result = writer.writeString(SDL, segment.sdl()); }
if (result != Result.SUCCESS) {
return result; if (segment.sdl() != null) {
} result = writer.writeString(SDL, segment.sdl());
} if (result != Result.SUCCESS) {
return result;
// Defer writing the length until all other fields of the segment header are written. }
// The length is then computed based on the current size of the underlying RowBuffer. }
// Because the length field is itself fixed, writing the length can never change the length.
// Defer writing the length until all other fields of the segment header are written.
int length = writer.length(); // The length is then computed based on the current size of the underlying RowBuffer.
result = writer.writeInt32(LENGTH, length); // Because the length field is itself fixed, writing the length can never change the length.
if (result != Result.SUCCESS) {
return result; int length = writer.length();
} result = writer.writeInt32(LENGTH, length);
if (result != Result.SUCCESS) {
checkState(length == writer.length()); return result;
return Result.SUCCESS; }
}
checkState(length == writer.length());
return Result.SUCCESS;
}
} }

View File

@@ -6,15 +6,15 @@ package com.azure.data.cosmos.serialization.hybridrow;
/** /**
* The literal null value. * The literal null value.
* <p> * <p>
* May be stored hybrid row to indicate the literal null value. Typically this value should * May be stored hybrid row to indicate the literal null value. Typically this value should not be used and the
* not be used and the corresponding column should be absent from the row. * corresponding column should be absent from the row.
*/ */
public final class NullValue { public final class NullValue {
/** /**
* The default null literal. * The default null literal.
* This is the same value as default({@link NullValue}). * This is the same value as default({@link NullValue}).
*/ */
public static final NullValue Default = new NullValue(); public static final NullValue DEFAULT = new NullValue();
/** /**
* Returns true if this is the same value as {@code other}. * Returns true if this is the same value as {@code other}.

View File

@@ -625,7 +625,7 @@ public final class RowBuffer {
this.readSparsePrimitiveTypeCode(edit, LayoutTypes.NULL); this.readSparsePrimitiveTypeCode(edit, LayoutTypes.NULL);
edit.endOffset(edit.valueOffset()); edit.endOffset(edit.valueOffset());
return NullValue.Default; return NullValue.DEFAULT;
} }
public Utf8String readSparsePath(@Nonnull final RowCursor edit) { public Utf8String readSparsePath(@Nonnull final RowCursor edit) {
@@ -843,22 +843,22 @@ public final class RowBuffer {
* *
* @param edit The iterator to advance. * @param edit The iterator to advance.
* *
* <paramref name="edit.Path"> * {@code edit.Path}
* On success, the path of the field at the given offset, otherwise * On success, the path of the field at the given offset, otherwise
* undefined. * undefined.
* </paramref> *
* <paramref name="edit.MetaOffset"> * {@code edit.MetaOffset}
* If found, the offset to the metadata of the field, otherwise a * If found, the offset to the metadata of the field, otherwise a
* location to insert the field. * location to insert the field.
* </paramref> *
* <paramref name="edit.cellType"> * {@code edit.cellType}
* If found, the layout code of the matching field found, otherwise * If found, the layout code of the matching field found, otherwise
* undefined. * undefined.
* </paramref> *
* <paramref name="edit.ValueOffset"> * {@code edit.ValueOffset}
* If found, the offset to the value of the field, otherwise * If found, the offset to the value of the field, otherwise
* undefined. * undefined.
* </paramref>. *.
* *
* @return {@code true} if there is another field; {@code false} if there is not. * @return {@code true} if there is another field; {@code false} if there is not.
*/ */
@@ -2814,26 +2814,26 @@ public final class RowBuffer {
* *
* @param edit The edit structure to fill in. * @param edit The edit structure to fill in.
* *
* <paramref name="edit.Path"> * {@code edit.Path}
* On success, the path of the field at the given offset, otherwise * On success, the path of the field at the given offset, otherwise
* undefined. * undefined.
* </paramref> *
* <paramref name="edit.MetaOffset"> * {@code edit.MetaOffset}
* On success, the offset to the metadata of the field, otherwise a * On success, the offset to the metadata of the field, otherwise a
* location to insert the field. * location to insert the field.
* </paramref> *
* <paramref name="edit.cellType"> * {@code edit.cellType}
* On success, the layout code of the existing field, otherwise * On success, the layout code of the existing field, otherwise
* undefined. * undefined.
* </paramref> *
* <paramref name="edit.TypeArgs"> * {@code edit.TypeArgs}
* On success, the type args of the existing field, otherwise * On success, the type args of the existing field, otherwise
* undefined. * undefined.
* </paramref> *
* <paramref name="edit.ValueOffset"> * {@code edit.ValueOffset}
* On success, the offset to the value of the field, otherwise * On success, the offset to the value of the field, otherwise
* undefined. * undefined.
* </paramref>. *.
*/ */
private void readSparseMetadata(@Nonnull final RowCursor edit) { private void readSparseMetadata(@Nonnull final RowCursor edit) {

View File

@@ -13,8 +13,6 @@ 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.RowCursors; import com.azure.data.cosmos.serialization.hybridrow.RowCursors;
import com.azure.data.cosmos.serialization.hybridrow.UnixDateTime; import com.azure.data.cosmos.serialization.hybridrow.UnixDateTime;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutSpanReadable;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutUtf8Readable;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutBinary; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutBinary;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutBoolean; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutBoolean;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutColumn; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutColumn;
@@ -30,7 +28,9 @@ import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutInt64;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutInt8; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutInt8;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutNull; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutNull;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutNullable; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutNullable;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutListReadable;
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.LayoutTypePrimitive;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutUDT; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutUDT;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutUInt16; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutUInt16;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutUInt32; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutUInt32;
@@ -126,7 +126,7 @@ public final class RowReader {
* Read the current field as a fixed length {@code MongoDbObjectId} value * Read the current field as a fixed length {@code MongoDbObjectId} value
* *
* @param value On success, receives the value, undefined otherwise * @param value On success, receives the value, undefined otherwise
* @return Success if the read is successful, an error code otherwise * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise.
*/ */
public Result ReadMongoDbObjectId(Out<?/* MongoDbObjectID */> value) { public Result ReadMongoDbObjectId(Out<?/* MongoDbObjectID */> value) {
// TODO: DANOBLE: Resurrect this method // TODO: DANOBLE: Resurrect this method
@@ -150,22 +150,6 @@ public final class RowReader {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
/**
* Read the current field as a variable length, UTF-8 encoded string value
*
* @param value On success, receives the value, undefined otherwise
* @return Success if the read is successful, an error code otherwise
*/
public Result ReadString(Out<String> value) {
Out<Utf8String> string = new Out<>();
Result result = this.readString(string);
value.set((result == Result.SUCCESS) ? string.get().toUtf16() : null);
string.get().release();
return result;
}
/** /**
* {@code true} if field has a value--if positioned on a field--undefined otherwise * {@code true} if field has a value--if positioned on a field--undefined otherwise
* <p> * <p>
@@ -264,64 +248,54 @@ public final class RowReader {
*/ */
public boolean read() { public boolean read() {
switch (this.state) { for (; ; ) {
case NONE: { switch (this.state) {
if (this.cursor.scopeType() instanceof LayoutUDT) {
this.state = States.SCHEMATIZED; case NONE: {
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java: this.state = this.cursor.scopeType() instanceof LayoutUDT ? States.SCHEMATIZED : States.SPARSE;
// goto case States.Schematized; break;
} else {
this.state = States.SPARSE;
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
// goto case States.Sparse;
} }
} case SCHEMATIZED: {
case SCHEMATIZED: {
this.columnIndex++; this.columnIndex++;
if (this.columnIndex >= this.schematizedCount) { if (this.columnIndex >= this.schematizedCount) {
this.state = States.SPARSE;
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java: this.state = States.SPARSE;
// goto case States.Sparse;
} else {
checkState(this.cursor.scopeType() instanceof LayoutUDT);
LayoutColumn column = this.columns.get(this.columnIndex);
if (!this.row.readBit(this.cursor.start(), column.nullBit())) {
break; // to skip schematized values if they aren't present
}
return true;
}
} }
case SPARSE: {
checkState(this.cursor.scopeType() instanceof LayoutUDT); if (!RowCursors.moveNext(this.cursor, this.row)) {
LayoutColumn column = this.columns.get(this.columnIndex); this.state = States.DONE;
break;
if (!this.row.readBit(this.cursor.start(), column.nullBit())) { }
// Skip schematized values if they aren't present return true;
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
// goto case States.Schematized;
} }
case DONE: {
return true; return false;
}
case SPARSE: {
if (!RowCursors.moveNext(this.cursor, this.row)) {
this.state = States.DONE;
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
// goto case States.Done;
} }
return true;
}
case DONE: {
return false;
} }
} }
return false;
} }
/** /**
* Read the current field as a variable length, sequence of bytes * Read the current field as a variable length, sequence of bytes
* *
* @param value On success, receives the value, undefined otherwise. * @param value On success, receives the value, undefined otherwise.
* @return Success if the read is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise.
*/ */
public Result readBinary(Out<ByteBuf> value) { public Result readBinary(Out<ByteBuf> value) {
@@ -336,6 +310,7 @@ public final class RowReader {
value.set(null); value.set(null);
return Result.TYPE_MISMATCH; return Result.TYPE_MISMATCH;
} }
value.set(this.row.readSparseBinary(this.cursor)); value.set(this.row.readSparseBinary(this.cursor));
return Result.SUCCESS; return Result.SUCCESS;
@@ -349,7 +324,7 @@ public final class RowReader {
* Read the current field as a variable length, sequence of bytes * Read the current field as a variable length, sequence of bytes
* *
* @param value On success, receives the value, undefined otherwise. * @param value On success, receives the value, undefined otherwise.
* @return Success if the read is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise.
*/ */
public Result readBinaryArray(Out<byte[]> value) { public Result readBinaryArray(Out<byte[]> value) {
@@ -369,7 +344,7 @@ public final class RowReader {
* Read the current field as a {@link Boolean} * Read the current field as a {@link Boolean}
* *
* @param value On success, receives the value, undefined otherwise. * @param value On success, receives the value, undefined otherwise.
* @return Success if the read is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise.
*/ */
public Result readBoolean(Out<Boolean> value) { public Result readBoolean(Out<Boolean> value) {
@@ -397,7 +372,7 @@ public final class RowReader {
* Read the current field as a fixed length {@code DateTime} value * Read the current field as a fixed length {@code DateTime} value
* *
* @param value On success, receives the value, undefined otherwise. * @param value On success, receives the value, undefined otherwise.
* @return Success if the read is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise.
*/ */
public Result readDateTime(Out<OffsetDateTime> value) { public Result readDateTime(Out<OffsetDateTime> value) {
@@ -425,7 +400,7 @@ public final class RowReader {
* Read the current field as a fixed length decimal value * Read the current field as a fixed length decimal value
* *
* @param value On success, receives the value, undefined otherwise. * @param value On success, receives the value, undefined otherwise.
* @return Success if the read is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise.
*/ */
public Result readDecimal(Out<BigDecimal> value) { public Result readDecimal(Out<BigDecimal> value) {
@@ -452,7 +427,7 @@ public final class RowReader {
* Read the current field as a fixed length, 128-bit, IEEE-encoded floating point value * Read the current field as a fixed length, 128-bit, IEEE-encoded floating point value
* *
* @param value On success, receives the value, undefined otherwise. * @param value On success, receives the value, undefined otherwise.
* @return Success if the read is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise.
*/ */
public Result readFloat128(Out<Float128> value) { public Result readFloat128(Out<Float128> value) {
@@ -479,7 +454,7 @@ public final class RowReader {
* Read the current field as a fixed length, 32-bit, IEEE-encoded floating point value * Read the current field as a fixed length, 32-bit, IEEE-encoded floating point value
* *
* @param value On success, receives the value, undefined otherwise. * @param value On success, receives the value, undefined otherwise.
* @return Success if the read is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise.
*/ */
public Result readFloat32(Out<Float> value) { public Result readFloat32(Out<Float> value) {
@@ -506,7 +481,7 @@ public final class RowReader {
* Read the current field as a fixed length, 64-bit, IEEE-encoded floating point value * Read the current field as a fixed length, 64-bit, IEEE-encoded floating point value
* *
* @param value On success, receives the value, undefined otherwise. * @param value On success, receives the value, undefined otherwise.
* @return Success if the read is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise.
*/ */
public Result readFloat64(Out<Double> value) { public Result readFloat64(Out<Double> value) {
@@ -533,7 +508,7 @@ public final class RowReader {
* Read the current field as a fixed length GUID value * Read the current field as a fixed length GUID value
* *
* @param value On success, receives the value, undefined otherwise. * @param value On success, receives the value, undefined otherwise.
* @return Success if the read is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise.
*/ */
public Result readGuid(Out<UUID> value) { public Result readGuid(Out<UUID> value) {
@@ -561,7 +536,7 @@ public final class RowReader {
* Read the current field as a fixed length, 16-bit, signed integer * Read the current field as a fixed length, 16-bit, signed integer
* *
* @param value On success, receives the value, undefined otherwise. * @param value On success, receives the value, undefined otherwise.
* @return Success if the read is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise.
*/ */
public Result readInt16(Out<Short> value) { public Result readInt16(Out<Short> value) {
@@ -588,7 +563,7 @@ public final class RowReader {
* Read the current field as a fixed length, 32-bit, signed integer * Read the current field as a fixed length, 32-bit, signed integer
* *
* @param value On success, receives the value, undefined otherwise. * @param value On success, receives the value, undefined otherwise.
* @return Success if the read is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise.
*/ */
public Result readInt32(Out<Integer> value) { public Result readInt32(Out<Integer> value) {
@@ -615,7 +590,7 @@ public final class RowReader {
* Read the current field as a fixed length, 64-bit, signed integer * Read the current field as a fixed length, 64-bit, signed integer
* *
* @param value On success, receives the value, undefined otherwise. * @param value On success, receives the value, undefined otherwise.
* @return Success if the read is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise.
*/ */
public Result readInt64(Out<Long> value) { public Result readInt64(Out<Long> value) {
@@ -642,7 +617,7 @@ public final class RowReader {
* Read the current field as a fixed length, 8-bit, signed integer * Read the current field as a fixed length, 8-bit, signed integer
* *
* @param value On success, receives the value, undefined otherwise. * @param value On success, receives the value, undefined otherwise.
* @return Success if the read is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise.
*/ */
public Result readInt8(Out<Byte> value) { public Result readInt8(Out<Byte> value) {
@@ -669,7 +644,7 @@ public final class RowReader {
* Read the current field as a null * Read the current field as a null
* *
* @param value On success, receives the value, undefined otherwise. * @param value On success, receives the value, undefined otherwise.
* @return Success if the read is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise.
*/ */
public Result readNull(Out<NullValue> value) { public Result readNull(Out<NullValue> value) {
@@ -693,7 +668,7 @@ public final class RowReader {
} }
/** /**
* Read the current field as a nested, structured, sparse scope * Read the current field as a nested, structured, sparse scope.
* <p> * <p>
* Child readers can be used to read all sparse scope types including typed and untyped objects, arrays, tuples, * Child readers can be used to read all sparse scope types including typed and untyped objects, arrays, tuples,
* set, and maps. * set, and maps.
@@ -717,9 +692,7 @@ public final class RowReader {
* Read the current field as a nested, structured, sparse scope * Read the current field as a nested, structured, sparse scope
* <p> * <p>
* Child readers can be used to read all sparse scope types including typed and untyped objects, arrays, tuples, * Child readers can be used to read all sparse scope types including typed and untyped objects, arrays, tuples,
* set, and maps. * set, and maps. Nested child readers are independent of their parent.
* <p>
* Nested child readers are independent of their parent.
*/ */
public @Nonnull RowReader readScope() { public @Nonnull RowReader readScope() {
RowCursor newScope = this.row.sparseIteratorReadScope(this.cursor, true); RowCursor newScope = this.row.sparseIteratorReadScope(this.cursor, true);
@@ -727,12 +700,28 @@ public final class RowReader {
} }
/** /**
* Read the current field as a variable length, UTF-8 encoded, string value * Read the current field as a variable length, UTF-8 encoded string value
* *
* @param value On success, receives the value, undefined otherwise * @param value On success, receives the value, undefined otherwise
* @return Success if the read is successful, an error code otherwise * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise.
*/ */
public Result readString(Out<Utf8String> value) { public Result readString(Out<String> value) {
Out<Utf8String> string = new Out<>();
Result result = this.readUtf8String(string);
value.set((result == Result.SUCCESS) ? string.get().toUtf16() : null);
string.get().release();
return result;
}
/**
* Read the current field as a variable length, UTF-8 encoded, string value.
*
* @param value On success, receives the value, undefined otherwise.
* @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise.
*/
public Result readUtf8String(Out<Utf8String> value) {
switch (this.state) { switch (this.state) {
@@ -754,10 +743,10 @@ public final class RowReader {
} }
/** /**
* Read the current field as a fixed length, 16-bit, unsigned integer * Read the current field as a fixed length, 16-bit, unsigned integer.
* *
* @param value On success, receives the value, undefined otherwise * @param value On success, receives the value, undefined otherwise.
* @return Success if the read is successful, an error code otherwise * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise.
*/ */
public Result readUInt16(Out<Integer> value) { public Result readUInt16(Out<Integer> value) {
@@ -784,7 +773,7 @@ public final class RowReader {
* Read the current field as a fixed length, 32-bit, unsigned integer * Read the current field as a fixed length, 32-bit, unsigned integer
* *
* @param value On success, receives the value, undefined otherwise * @param value On success, receives the value, undefined otherwise
* @return Success if the read is successful, an error code otherwise * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise.
*/ */
public Result readUInt32(Out<Long> value) { public Result readUInt32(Out<Long> value) {
@@ -812,7 +801,7 @@ public final class RowReader {
* Read the current field as a fixed length, 64-bit, unsigned integer * Read the current field as a fixed length, 64-bit, unsigned integer
* *
* @param value On success, receives the value, undefined otherwise * @param value On success, receives the value, undefined otherwise
* @return Success if the read is successful, an error code otherwise * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise.
*/ */
public Result readUInt64(Out<Long> value) { public Result readUInt64(Out<Long> value) {
@@ -839,7 +828,7 @@ public final class RowReader {
* Read the current field as a fixed length, 8-bit, unsigned integer * Read the current field as a fixed length, 8-bit, unsigned integer
* *
* @param value On success, receives the value, undefined otherwise * @param value On success, receives the value, undefined otherwise
* @return Success if the read is successful, an error code otherwise * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise.
*/ */
public Result readUInt8(Out<Short> value) { public Result readUInt8(Out<Short> value) {
@@ -866,7 +855,7 @@ public final class RowReader {
* Read the current field as a fixed length {@link UnixDateTime} value * Read the current field as a fixed length {@link UnixDateTime} value
* *
* @param value On success, receives the value, undefined otherwise * @param value On success, receives the value, undefined otherwise
* @return Success if the read is successful, an error code otherwise * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise.
*/ */
public Result readUnixDateTime(Out<UnixDateTime> value) { public Result readUnixDateTime(Out<UnixDateTime> value) {
@@ -893,7 +882,7 @@ public final class RowReader {
* Read the current field as a variable length, 7-bit encoded, signed integer * Read the current field as a variable length, 7-bit encoded, signed integer
* *
* @param value On success, receives the value, undefined otherwise * @param value On success, receives the value, undefined otherwise
* @return Success if the read is successful, an error code otherwise * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise.
*/ */
public Result readVarInt(Out<Long> value) { public Result readVarInt(Out<Long> value) {
@@ -920,7 +909,7 @@ public final class RowReader {
* Read the current field as a variable length, 7-bit encoded, unsigned integer * Read the current field as a variable length, 7-bit encoded, unsigned integer
* *
* @param value On success, receives the value, undefined otherwise * @param value On success, receives the value, undefined otherwise
* @return Success if the read is successful, an error code otherwise * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise.
*/ */
public Result readVarUInt(Out<Long> value) { public Result readVarUInt(Out<Long> value) {
@@ -1012,14 +1001,14 @@ public final class RowReader {
* Reads a generic schematized field value via the scope's layout * Reads a generic schematized field value via the scope's layout
* *
* @param value On success, receives the value, undefined otherwise * @param value On success, receives the value, undefined otherwise
* @return Success if the read is successful, an error code otherwise * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise.
*/ */
private <TValue> Result readPrimitiveValue(Out<TValue> value) { private <TValue> Result readPrimitiveValue(Out<TValue> value) {
final LayoutColumn column = this.columns.get(this.columnIndex); final LayoutColumn column = this.columns.get(this.columnIndex);
final LayoutType type = this.columns.get(this.columnIndex).type(); final LayoutType type = this.columns.get(this.columnIndex).type();
if (!(type instanceof LayoutType<TValue>)) { if (!(type instanceof LayoutTypePrimitive)) {
value.set(null); value.set(null);
return Result.TYPE_MISMATCH; return Result.TYPE_MISMATCH;
} }
@@ -1028,42 +1017,9 @@ public final class RowReader {
switch (storage) { switch (storage) {
case FIXED: case FIXED:
return type.<LayoutType<TValue>>typeAs().readFixed(this.row, this.cursor, column, value); return type.<LayoutTypePrimitive<TValue>>typeAs().readFixed(this.row, this.cursor, column, value);
case VARIABLE: case VARIABLE:
return type.<LayoutType<TValue>>typeAs().readVariable(this.row, this.cursor, column, value); return type.<LayoutTypePrimitive<TValue>>typeAs().readVariable(this.row, this.cursor, column, value);
default:
assert false : lenientFormat("expected FIXED or VARIABLE column storage, not %s", storage);
value.set(null);
return Result.FAILURE;
}
}
/**
* Reads a generic schematized field value via the scope's layout
*
* @param value On success, receives the value, undefined otherwise
* @return {@link Result#SUCCESS} if the read is successful; an error {@link Result} otherwise
*/
private Result readPrimitiveValue(Out<Utf8String> value) {
LayoutColumn column = this.columns.get(this.columnIndex);
LayoutType type = this.columns.get(this.columnIndex).type();
if (!(type instanceof LayoutUtf8Readable)) {
value.set(null);
return Result.TYPE_MISMATCH;
}
StorageKind storage = column == null ? StorageKind.NONE : column.storage();
switch (storage) {
case FIXED:
return type.<LayoutUtf8Readable>typeAs().readFixed(this.row, this.cursor, column, value);
case VARIABLE:
return type.<LayoutUtf8Readable>typeAs().readVariable(this.row, this.cursor, column, value);
default: default:
assert false : lenientFormat("expected FIXED or VARIABLE column storage, not %s", storage); assert false : lenientFormat("expected FIXED or VARIABLE column storage, not %s", storage);
value.set(null); value.set(null);
@@ -1071,19 +1027,52 @@ public final class RowReader {
} }
} }
// /**
// * Reads a generic schematized field value via the scope's layout
// *
// * @param value On success, receives the value, undefined otherwise
// * @return {@link Result#SUCCESS} if the read is successful; an error {@link Result} otherwise
// */
// private Result readPrimitiveValue(Out<Utf8String> value) {
//
// LayoutColumn column = this.columns.get(this.columnIndex);
// LayoutType type = this.columns.get(this.columnIndex).type();
//
// if (!(type instanceof LayoutUtf8Readable)) {
// value.set(null);
// return Result.TYPE_MISMATCH;
// }
//
// StorageKind storage = column == null ? StorageKind.NONE : column.storage();
//
// switch (storage) {
//
// case FIXED:
// return type.<LayoutUtf8Readable>typeAs().readFixed(this.row, this.cursor, column, value);
//
// case VARIABLE:
// return type.<LayoutUtf8Readable>typeAs().readVariable(this.row, this.cursor, column, value);
//
// default:
// assert false : lenientFormat("expected FIXED or VARIABLE column storage, not %s", storage);
// value.set(null);
// return Result.FAILURE;
// }
// }
//
/** /**
* Reads a generic schematized field value via the scope's layout * Reads a generic schematized field value via the scope's layout
* *
* @param <TElement> The sub-element type of the field * @param <TElement> The sub-element type of the field
* @param value On success, receives the value, undefined otherwise * @param value On success, receives the value, undefined otherwise
* @return Success if the read is successful, an error code otherwise * @return {@link Result#SUCCESS} if the read is successful, an error {@link Result} otherwise.
*/ */
private <TElement> Result readPrimitiveValue(Out<List<TElement>> value) { private <TElement> Result readPrimitiveValueList(Out<List<TElement>> value) {
LayoutColumn column = this.columns.get(this.columnIndex); LayoutColumn column = this.columns.get(this.columnIndex);
LayoutType type = this.columns.get(this.columnIndex).type(); LayoutType type = this.columns.get(this.columnIndex).type();
if (!(type instanceof LayoutSpanReadable<?>)) { if (!(type instanceof LayoutListReadable<?>)) {
value.set(null); value.set(null);
return Result.TYPE_MISMATCH; return Result.TYPE_MISMATCH;
} }
@@ -1093,10 +1082,10 @@ public final class RowReader {
switch (storage) { switch (storage) {
case FIXED: case FIXED:
return type.<LayoutSpanReadable<TElement>>typeAs().readFixed(this.row, this.cursor, column, value); return type.<LayoutListReadable<TElement>>typeAs().readFixedList(this.row, this.cursor, column, value);
case VARIABLE: case VARIABLE:
return type.<LayoutSpanReadable<TElement>>typeAs().readVariable(this.row, this.cursor, column, value); return type.<LayoutListReadable<TElement>>typeAs().readVariableList(this.row, this.cursor, column, value);
default: default:
assert false : lenientFormat("expected FIXED or VARIABLE column storage, not %s", storage); assert false : lenientFormat("expected FIXED or VARIABLE column storage, not %s", storage);

View File

@@ -14,7 +14,7 @@ public final class RowReaderExtensions {
/** /**
* Read the current field as a nested, structured, sparse scope containing a linear collection of zero or more * Read the current field as a nested, structured, sparse scope containing a linear collection of zero or more
* items. * items.
* <typeparam name="TItem">The type of the items within the collection.</typeparam> * @param <TItem> The type of the items within the collection.
* *
* @param reader A forward-only cursor for reading the collection. * @param reader A forward-only cursor for reading the collection.
* @param deserializer A function that reads one item from the collection. * @param deserializer A function that reads one item from the collection.

View File

@@ -16,10 +16,11 @@ import com.azure.data.cosmos.serialization.hybridrow.RowCursors;
import com.azure.data.cosmos.serialization.hybridrow.UnixDateTime; import com.azure.data.cosmos.serialization.hybridrow.UnixDateTime;
import com.azure.data.cosmos.serialization.hybridrow.layouts.Layout; import com.azure.data.cosmos.serialization.hybridrow.layouts.Layout;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutColumn; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutColumn;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutListWritable;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutNullable; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutNullable;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutResolver; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutResolver;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutSpanWritable;
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.LayoutTypePrimitive;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTypedMap; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTypedMap;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTypes; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTypes;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutUDT; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutUDT;
@@ -30,10 +31,12 @@ import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgumentList;
import com.azure.data.cosmos.serialization.hybridrow.layouts.UpdateOptions; import com.azure.data.cosmos.serialization.hybridrow.layouts.UpdateOptions;
import com.azure.data.cosmos.serialization.hybridrow.schemas.StorageKind; import com.azure.data.cosmos.serialization.hybridrow.schemas.StorageKind;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.OffsetDateTime;
import java.util.UUID; import java.util.UUID;
import java.util.function.Consumer;
public final class RowWriter { public final class RowWriter {
@@ -80,11 +83,10 @@ public final class RowWriter {
* *
* @param path The scope-relative path of the field to write. * @param path The scope-relative path of the field to write.
* @param value The value to write. * @param value The value to write.
* @return Success if the write is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
*/ */
public Result WriteBinary(UtfAnyString path, byte[] value) { public Result WriteBinary(UtfAnyString path, byte[] value) {
return this.writePrimitive(path, value, LayoutTypes.BINARY, return this.WriteBinary(path, Unpooled.wrappedBuffer(value));
(ref RowWriter w, byte[] v) -> w.row.writeSparseBinary(ref w.cursor, v, UpdateOptions.UPSERT));
} }
/** /**
@@ -92,24 +94,11 @@ public final class RowWriter {
* *
* @param path The scope-relative path of the field to write. * @param path The scope-relative path of the field to write.
* @param value The value to write. * @param value The value to write.
* @return Success if the write is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
*/ */
public Result WriteBinary(UtfAnyString path, ByteBuf value) { public Result WriteBinary(UtfAnyString path, ByteBuf value) {
return this.writePrimitive(path, value, LayoutTypes.BINARY, return this.writePrimitive(path, value, LayoutTypes.BINARY, (ByteBuf v) ->
(ref RowWriter w, ByteBuf v) -> w.row.writeSparseBinary(ref w.cursor, v, UpdateOptions.UPSERT)); this.row.writeSparseBinary(this.cursor, v, UpdateOptions.UPSERT));
}
/**
* Write a field as a variable length, sequence of bytes.
*
* @param path The scope-relative path of the field to write.
* @param value The value to write.
* @return Success if the write is successful, an error code otherwise.
*/
public Result WriteBinary(UtfAnyString path, ReadOnlySequence<Byte> value) {
return this.writePrimitive(path, value, LayoutTypes.BINARY,
(ref RowWriter w, ReadOnlySequence<Byte> v) -> w.row.writeSparseBinary(ref w.cursor, v,
UpdateOptions.UPSERT));
} }
/** /**
@@ -117,21 +106,21 @@ public final class RowWriter {
* *
* @param path The scope-relative path of the field to write. * @param path The scope-relative path of the field to write.
* @param value The value to write. * @param value The value to write.
* @return Success if the write is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
*/ */
public Result WriteBoolean(UtfAnyString path, boolean value) { public Result WriteBoolean(UtfAnyString path, boolean value) {
return this.writePrimitive(path, value, LayoutTypes.BOOLEAN, return this.writePrimitive(path, value, LayoutTypes.BOOLEAN, (Boolean v) ->
(ref RowWriter w, boolean v) -> w.row.writeSparseBool(ref w.cursor, v, UpdateOptions.UPSERT)); this.row.writeSparseBoolean(this.cursor, value, UpdateOptions.UPSERT));
} }
/** /**
* Write an entire row in a streaming left-to-right way. * Write an entire row in a streaming left-to-right way.
* <typeparam name="TContext">The type of the context value to pass to <paramref name="func" />.</typeparam>
* *
* @param row The row to write. * @param <TContext> The type of the context value to pass to {@code func}.
* @param context A context value to pass to <paramref name="func" />. * @param row The row to write.
* @param func A function to write the entire row. * @param context A context value to pass to {@code func}.
* @return Success if the write is successful, an error code otherwise. * @param func A function to write the entire row.
* @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
*/ */
public static <TContext> Result WriteBuffer( public static <TContext> Result WriteBuffer(
Reference<RowBuffer> row, TContext context, WriterFunc<TContext> func) { Reference<RowBuffer> row, TContext context, WriterFunc<TContext> func) {
@@ -152,35 +141,27 @@ public final class RowWriter {
} }
/** /**
* Write a field as a fixed length {@link DateTime} value. * Write a field as a fixed length {@code DateTime} value.
* *
* @param path The scope-relative path of the field to write. * @param path The scope-relative path of the field to write.
* @param value The value to write. * @param value The value to write.
* @return Success if the write is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
*/ */
public Result WriteDateTime(UtfAnyString path, LocalDateTime value) { public Result writeDateTime(UtfAnyString path, OffsetDateTime value) {
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not return this.writePrimitive(path, value, LayoutTypes.DATE_TIME, (OffsetDateTime v) ->
// converted by C# to Java Converter: this.row.writeSparseDateTime(this.cursor, v, UpdateOptions.UPSERT));
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.writePrimitive(path, value, LayoutTypes.DATE_TIME,
(ref RowWriter w, LocalDateTime v) -> w.row.writeSparseDateTime(ref w.cursor, v, UpdateOptions.UPSERT));
} }
/** /**
* Write a field as a fixed length {@link decimal} value. * Write a field as a fixed length {@code Decimal} value.
* *
* @param path The scope-relative path of the field to write. * @param path The scope-relative path of the field to write.
* @param value The value to write. * @param value The value to write.
* @return Success if the write is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
*/ */
public Result WriteDecimal(UtfAnyString path, BigDecimal value) { public Result writeDecimal(UtfAnyString path, BigDecimal value) {
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not return this.writePrimitive(path, value, LayoutTypes.DECIMAL, (BigDecimal v) ->
// converted by C# to Java Converter: this.row.writeSparseDecimal(this.cursor, v, UpdateOptions.UPSERT));
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.writePrimitive(path, value, LayoutTypes.DECIMAL,
(ref RowWriter w, BigDecimal v) -> w.row.writeSparseDecimal(ref w.cursor, v, UpdateOptions.UPSERT));
} }
/** /**
@@ -188,15 +169,11 @@ public final class RowWriter {
* *
* @param path The scope-relative path of the field to write. * @param path The scope-relative path of the field to write.
* @param value The value to write. * @param value The value to write.
* @return Success if the write is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
*/ */
public Result WriteFloat128(UtfAnyString path, Float128 value) { public Result writeFloat128(UtfAnyString path, Float128 value) {
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not return this.writePrimitive(path, value, LayoutTypes.FLOAT_128, (Float128 v) ->
// converted by C# to Java Converter: this.row.writeSparseFloat128(this.cursor, v, UpdateOptions.UPSERT));
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.writePrimitive(path, value, LayoutTypes.FLOAT_128,
(ref RowWriter w, Float128 v) -> w.row.writeSparseFloat128(ref w.cursor, v, UpdateOptions.UPSERT));
} }
/** /**
@@ -204,15 +181,11 @@ public final class RowWriter {
* *
* @param path The scope-relative path of the field to write. * @param path The scope-relative path of the field to write.
* @param value The value to write. * @param value The value to write.
* @return Success if the write is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
*/ */
public Result WriteFloat32(UtfAnyString path, float value) { public Result writeFloat32(UtfAnyString path, float value) {
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not return this.writePrimitive(path, value, LayoutTypes.FLOAT_32, (Float v) ->
// converted by C# to Java Converter: this.row.writeSparseFloat32(this.cursor, v, UpdateOptions.UPSERT));
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.writePrimitive(path, value, LayoutTypes.FLOAT_32,
(ref RowWriter w, float v) -> w.row.writeSparseFloat32(ref w.cursor, v, UpdateOptions.UPSERT));
} }
/** /**
@@ -220,31 +193,23 @@ public final class RowWriter {
* *
* @param path The scope-relative path of the field to write. * @param path The scope-relative path of the field to write.
* @param value The value to write. * @param value The value to write.
* @return Success if the write is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
*/ */
public Result WriteFloat64(UtfAnyString path, double value) { public Result writeFloat64(UtfAnyString path, double value) {
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not return this.writePrimitive(path, value, LayoutTypes.FLOAT_64, (Double v) ->
// converted by C# to Java Converter: this.row.writeSparseFloat64(this.cursor, v, UpdateOptions.UPSERT));
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.writePrimitive(path, value, LayoutTypes.FLOAT_64,
(ref RowWriter w, double v) -> w.row.writeSparseFloat64(ref w.cursor, v, UpdateOptions.UPSERT));
} }
/** /**
* Write a field as a fixed length {@link Guid} value. * Write a field as a fixed length {@code Guid} value.
* *
* @param path The scope-relative path of the field to write. * @param path The scope-relative path of the field to write.
* @param value The value to write. * @param value The value to write.
* @return Success if the write is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
*/ */
public Result WriteGuid(UtfAnyString path, UUID value) { public Result writeGuid(UtfAnyString path, UUID value) {
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not return this.writePrimitive(path, value, LayoutTypes.GUID, (UUID v) ->
// converted by C# to Java Converter: this.row.writeSparseGuid(this.cursor, v, UpdateOptions.UPSERT));
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.writePrimitive(path, value, LayoutTypes.GUID,
(ref RowWriter w, UUID v) -> w.row.writeSparseGuid(ref w.cursor, v, UpdateOptions.UPSERT));
} }
/** /**
@@ -252,31 +217,11 @@ public final class RowWriter {
* *
* @param path The scope-relative path of the field to write. * @param path The scope-relative path of the field to write.
* @param value The value to write. * @param value The value to write.
* @return Success if the write is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
*/ */
public Result WriteInt16(UtfAnyString path, short value) { public Result writeInt16(UtfAnyString path, short value) {
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not return this.writePrimitive(path, value, LayoutTypes.INT_16, (Short v) ->
// converted by C# to Java Converter: this.row.writeSparseInt16(this.cursor, v, UpdateOptions.UPSERT));
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.writePrimitive(path, value, LayoutTypes.INT_16,
(ref RowWriter w, short v) -> w.row.writeSparseInt16(ref w.cursor, v, UpdateOptions.UPSERT));
}
/**
* Write a field as a fixed length, 32-bit, signed integer.
*
* @param path The scope-relative path of the field to write.
* @param value The value to write.
* @return Success if the write is successful, an error code otherwise.
*/
public Result writeInt32(UtfAnyString path, int value) {
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not
// converted by C# to Java Converter:
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.writePrimitive(path, value, LayoutTypes.INT_32,
(ref RowWriter w, int v) -> w.row.writeSparseInt32(ref w.cursor, v, UpdateOptions.UPSERT));
} }
/** /**
@@ -284,15 +229,11 @@ public final class RowWriter {
* *
* @param path The scope-relative path of the field to write. * @param path The scope-relative path of the field to write.
* @param value The value to write. * @param value The value to write.
* @return Success if the write is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
*/ */
public Result WriteInt64(UtfAnyString path, long value) { public Result writeInt64(UtfAnyString path, long value) {
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not return this.writePrimitive(path, value, LayoutTypes.INT_64, (Long v) ->
// converted by C# to Java Converter: this.row.writeSparseInt64(this.cursor, v, UpdateOptions.UPSERT));
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.writePrimitive(path, value, LayoutTypes.INT_64,
(ref RowWriter w, long v) -> w.row.writeSparseInt64(ref w.cursor, v, UpdateOptions.UPSERT));
} }
/** /**
@@ -300,15 +241,22 @@ public final class RowWriter {
* *
* @param path The scope-relative path of the field to write. * @param path The scope-relative path of the field to write.
* @param value The value to write. * @param value The value to write.
* @return Success if the write is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
*/ */
public Result WriteInt8(UtfAnyString path, byte value) { public Result writeInt8(UtfAnyString path, byte value) {
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not return this.writePrimitive(path, value, LayoutTypes.INT_8, (Byte v) ->
// converted by C# to Java Converter: this.row.writeSparseInt8(this.cursor, v, UpdateOptions.UPSERT));
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these }
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.writePrimitive(path, value, LayoutTypes.INT_8, /**
(ref RowWriter w, byte v) -> w.row.writeSparseInt8(ref w.cursor, v, UpdateOptions.UPSERT)); * Write a field as a {@code null}.
*
* @param path The scope-relative path of the field to write.
* @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
*/
public Result writeNull(UtfAnyString path) {
return this.writePrimitive(path, NullValue.DEFAULT, LayoutTypes.NULL, (NullValue v) ->
this.row.writeSparseNull(this.cursor, v, UpdateOptions.UPSERT));
} }
// TODO: DANOBLE: Resurrect this method // TODO: DANOBLE: Resurrect this method
@@ -317,27 +265,18 @@ public final class RowWriter {
// * // *
// * @param path The scope-relative path of the field to write. // * @param path The scope-relative path of the field to write.
// * @param value The value to write. // * @param value The value to write.
// * @return Success if the write is successful, an error code otherwise. // * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
// */ // */
// public Result WriteMongoDbObjectId(UtfAnyString path, MongoDbObjectId value) { // public Result WriteMongoDbObjectId(UtfAnyString path, MongoDbObjectId value) {
// throw new UnsupportedOperationException(); // throw new UnsupportedOperationException();
// // return this.writePrimitive(path, value, LayoutTypes.MongoDbObjectId, (ref RowWriter w, MongoDbObjectId v) -> w.row.writeSparseMongoDbObjectId(ref w.cursor, v, UpdateOptions.UPSERT)); // // return this.writePrimitive(path, value, LayoutTypes.MongoDbObjectId, (ref RowWriter w, MongoDbObjectId v) -> w.row.writeSparseMongoDbObjectId(ref w.cursor, v, UpdateOptions.UPSERT));
// } // }
/** public <TContext> Result WriteScope(
* Write a field as a {@link t:null}. UtfAnyString path, TypeArgument typeArg, TContext context, WriterFunc<TContext> func) {
*
* @param path The scope-relative path of the field to write.
* @return Success if the write is successful, an error code otherwise.
*/
public Result WriteNull(UtfAnyString path) {
return this.writePrimitive(path, NullValue.Default, LayoutTypes.NULL,
(ref RowWriter w, NullValue v) -> w.row.writeSparseNull(ref w.cursor, v, UpdateOptions.UPSERT));
}
public <TContext> Result WriteScope(UtfAnyString path, TypeArgument typeArg, TContext context,
WriterFunc<TContext> func) {
LayoutType type = typeArg.type(); LayoutType type = typeArg.type();
Result result = this.prepareSparseWrite(path, typeArg); Result result = this.prepareSparseWrite(path, typeArg);
if (result != Result.SUCCESS) { if (result != Result.SUCCESS) {
return result; return result;
@@ -543,16 +482,15 @@ public final class RowWriter {
} }
/** /**
* Write a field as a variable length, UTF8 encoded, string value. * Write a field as a fixed length, 32-bit, signed integer.
* *
* @param path The scope-relative path of the field to write. * @param path The scope-relative path of the field to write.
* @param value The value to write. * @param value The value to write.
* @return Success if the write is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
*/ */
public Result writeString(UtfAnyString path, String value) { public Result writeInt32(UtfAnyString path, int value) {
return this.writePrimitive(path, value, LayoutTypes.UTF_8, return this.writePrimitive(path, value, LayoutTypes.INT_32, (RowWriter writer, int v) ->
(ref RowWriter w, String v) -> w.row.writeSparseString(ref w.cursor, Utf8Span.TranscodeUtf16(v), writer.row.writeSparseInt32(writer.cursor, v, UpdateOptions.UPSERT));
UpdateOptions.UPSERT));
} }
/** /**
@@ -560,15 +498,30 @@ public final class RowWriter {
* *
* @param path The scope-relative path of the field to write. * @param path The scope-relative path of the field to write.
* @param value The value to write. * @param value The value to write.
* @return Success if the write is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
*/
public Result writeString(UtfAnyString path, String value) {
// TODO: DANOBLE: RowBuffer should support writing String values directly (without conversion to Utf8String)
Utf8String string = Utf8String.transcodeUtf16(value);
assert string != null;
try {
return this.writePrimitive(path, value, LayoutTypes.UTF_8, (RowWriter writer, String v) ->
writer.row.writeSparseString(writer.cursor, string, UpdateOptions.UPSERT));
} finally {
string.release();
}
}
/**
* Write a field as a variable length, UTF8 encoded, string value.
*
* @param path The scope-relative path of the field to write.
* @param value The value to write.
* @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
*/ */
public Result writeString(UtfAnyString path, Utf8String value) { public Result writeString(UtfAnyString path, Utf8String value) {
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not return this.writePrimitive(path, value, LayoutTypes.UTF_8, (RowWriter writer, Utf8String v) ->
// converted by C# to Java Converter: writer.row.writeSparseString(writer.cursor, v, UpdateOptions.UPSERT));
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.writePrimitive(path, value, LayoutTypes.UTF_8,
(ref RowWriter w, Utf8Span v) -> w.row.writeSparseString(ref w.cursor, v, UpdateOptions.UPSERT));
} }
/** /**
@@ -576,20 +529,11 @@ public final class RowWriter {
* *
* @param path The scope-relative path of the field to write. * @param path The scope-relative path of the field to write.
* @param value The value to write. * @param value The value to write.
* @return Success if the write is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
*/ */
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public Result WriteUInt16(UtfAnyString path, ushort value)
public Result writeUInt16(UtfAnyString path, short value) { public Result writeUInt16(UtfAnyString path, short value) {
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not return this.writePrimitive(path, value, LayoutTypes.UINT_16, (RowWriter writer, short v) ->
// converted by C# to Java Converter: writer.row.writeSparseUInt16(writer.cursor, v, UpdateOptions.UPSERT));
// 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:
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: return this.writePrimitive(path, value, LayoutTypes.UInt16, (ref RowWriter w, ushort v) => w
// .row.writeSparseUInt16(ref w.cursor, v, UpdateOptions.Upsert));
return this.writePrimitive(path, value, LayoutTypes.UINT_16,
(ref RowWriter w, short v) -> w.row.writeSparseUInt16(ref w.cursor, v, UpdateOptions.UPSERT));
} }
/** /**
@@ -597,20 +541,11 @@ public final class RowWriter {
* *
* @param path The scope-relative path of the field to write. * @param path The scope-relative path of the field to write.
* @param value The value to write. * @param value The value to write.
* @return Success if the write is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
*/ */
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public Result WriteUInt32(UtfAnyString path, uint value)
public Result writeUInt32(UtfAnyString path, int value) { public Result writeUInt32(UtfAnyString path, int value) {
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not return this.writePrimitive(path, value, LayoutTypes.UINT_32, (RowWriter writer, int v) ->
// converted by C# to Java Converter: writer.row.writeSparseUInt32(writer.cursor, v, UpdateOptions.UPSERT));
// 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:
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: return this.writePrimitive(path, value, LayoutTypes.UInt32, (ref RowWriter w, uint v) => w
// .row.writeSparseUInt32(ref w.cursor, v, UpdateOptions.Upsert));
return this.writePrimitive(path, value, LayoutTypes.UINT_32,
(ref RowWriter w, int v) -> w.row.writeSparseUInt32(ref w.cursor, v, UpdateOptions.UPSERT));
} }
/** /**
@@ -618,20 +553,11 @@ public final class RowWriter {
* *
* @param path The scope-relative path of the field to write. * @param path The scope-relative path of the field to write.
* @param value The value to write. * @param value The value to write.
* @return Success if the write is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
*/ */
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public Result WriteUInt64(UtfAnyString path, ulong value)
public Result writeUInt64(UtfAnyString path, long value) { public Result writeUInt64(UtfAnyString path, long value) {
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not return this.writePrimitive(path, value, LayoutTypes.UINT_64, (RowWriter writer, long v) ->
// converted by C# to Java Converter: writer.row.writeSparseUInt64(writer.cursor, v, UpdateOptions.UPSERT));
// 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:
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: return this.writePrimitive(path, value, LayoutTypes.UInt64, (ref RowWriter w, ulong v) => w
// .row.writeSparseUInt64(ref w.cursor, v, UpdateOptions.Upsert));
return this.writePrimitive(path, value, LayoutTypes.UINT_64,
(ref RowWriter w, long v) -> w.row.writeSparseUInt64(ref w.cursor, v, UpdateOptions.UPSERT));
} }
/** /**
@@ -639,20 +565,11 @@ public final class RowWriter {
* *
* @param path The scope-relative path of the field to write. * @param path The scope-relative path of the field to write.
* @param value The value to write. * @param value The value to write.
* @return Success if the write is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
*/ */
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public Result WriteUInt8(UtfAnyString path, byte value)
public Result writeUInt8(UtfAnyString path, byte value) { public Result writeUInt8(UtfAnyString path, byte value) {
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not return this.writePrimitive(path, value, LayoutTypes.UINT_8, (RowWriter writer, byte v) ->
// converted by C# to Java Converter: writer.row.writeSparseUInt8(writer.cursor, v, UpdateOptions.UPSERT));
// 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:
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: return this.writePrimitive(path, value, LayoutTypes.UInt8, (ref RowWriter w, byte v) => w.row
// .writeSparseUInt8(ref w.cursor, v, UpdateOptions.Upsert));
return this.writePrimitive(path, value, LayoutTypes.UINT_8,
(ref RowWriter w, byte v) -> w.row.writeSparseUInt8(ref w.cursor, v, UpdateOptions.UPSERT));
} }
/** /**
@@ -660,16 +577,11 @@ public final class RowWriter {
* *
* @param path The scope-relative path of the field to write. * @param path The scope-relative path of the field to write.
* @param value The value to write. * @param value The value to write.
* @return Success if the write is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
*/ */
public Result writeUnixDateTime(UtfAnyString path, UnixDateTime value) { public Result writeUnixDateTime(UtfAnyString path, UnixDateTime value) {
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not return this.writePrimitive(path, value, LayoutTypes.UNIX_DATE_TIME, (RowWriter writer, UnixDateTime v) ->
// converted by C# to Java Converter: writer.row.writeSparseUnixDateTime(writer.cursor, v, UpdateOptions.UPSERT));
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.writePrimitive(path, value, LayoutTypes.UNIX_DATE_TIME,
(ref RowWriter w, UnixDateTime v) -> w.row.writeSparseUnixDateTime(ref w.cursor, v,
UpdateOptions.UPSERT));
} }
/** /**
@@ -677,15 +589,11 @@ public final class RowWriter {
* *
* @param path The scope-relative path of the field to write. * @param path The scope-relative path of the field to write.
* @param value The value to write. * @param value The value to write.
* @return Success if the write is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
*/ */
public Result writeVarInt(UtfAnyString path, long value) { public Result writeVarInt(UtfAnyString path, long value) {
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not return this.writePrimitive(path, value, LayoutTypes.VAR_INT, (RowWriter writer, long v) ->
// converted by C# to Java Converter: writer.row.writeSparseVarInt(writer.cursor, v, UpdateOptions.UPSERT));
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.writePrimitive(path, value, LayoutTypes.VAR_INT,
(ref RowWriter w, long v) -> w.row.writeSparseVarInt(ref w.cursor, v, UpdateOptions.UPSERT));
} }
/** /**
@@ -693,20 +601,11 @@ public final class RowWriter {
* *
* @param path The scope-relative path of the field to write. * @param path The scope-relative path of the field to write.
* @param value The value to write. * @param value The value to write.
* @return Success if the write is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
*/ */
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public Result WriteVarUInt(UtfAnyString path, ulong value)
public Result writeVarUInt(UtfAnyString path, long value) { public Result writeVarUInt(UtfAnyString path, long value) {
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not return this.writePrimitive(path, value, LayoutTypes.VAR_UINT, (RowWriter writer, long v) ->
// converted by C# to Java Converter: writer.row.writeSparseVarUInt(writer.cursor, v, UpdateOptions.UPSERT));
// 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:
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: return this.writePrimitive(path, value, LayoutTypes.VarUInt, (ref RowWriter w, ulong v) => w
// .row.writeSparseVarUInt(ref w.cursor, v, UpdateOptions.Upsert));
return this.writePrimitive(path, value, LayoutTypes.VAR_UINT,
(ref RowWriter w, long v) -> w.row.writeSparseVarUInt(ref w.cursor, v, UpdateOptions.UPSERT));
} }
/** /**
@@ -740,15 +639,57 @@ public final class RowWriter {
/** /**
* Helper for writing a primitive value. * Helper for writing a primitive value.
* <typeparam name="TLayoutType">The type of layout type.</typeparam>
* *
* @param path The scope-relative path of the field to write. * @param <TLayoutType> The type of layout type.
* @param value The value to write. * @param path The scope-relative path of the field to write.
* @param type The layout type. * @param value The value to write.
* @param sparse The {@link RowBuffer} access method for <paramref name="type" />. * @param type The layout type.
* @return Success if the write is successful, an error code otherwise. * @param sparse The {@link RowBuffer} access method for {@code type}.
* @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
*/ */
private <TLayoutType extends LayoutType<String> & LayoutUtf8Writable> Result writePrimitive(UtfAnyString path, Utf8String value, TLayoutType type, AccessUtf8SpanMethod sparse) { private <TLayoutType extends LayoutTypePrimitive<String> & LayoutUtf8Writable>
Result writePrimitive(UtfAnyString path, Utf8String value, TLayoutType type, AccessUtf8SpanMethod sparse) {
Result result = Result.NOT_FOUND;
if (this.cursor.scopeType() instanceof LayoutUDT) {
result = this.writeSchematizedValue(path, value);
}
if (result == Result.NOT_FOUND) {
// Write sparse value.
result = this.prepareSparseWrite(path, type.typeArg());
if (result != Result.SUCCESS) {
return result;
}
Reference<RowWriter> tempReference_this =
new Reference<RowWriter>(this);
// TODO: C# TO JAVA CONVERTER: The following line could not be converted:
sparse(ref this, value)
this = tempReference_this.get();
Reference<RowBuffer> tempReference_row =
new Reference<RowBuffer>(this.row);
RowCursors.moveNext(this.cursor,
tempReference_row);
this.row = tempReference_row.get();
}
return result;
}
/**
* Helper for writing a primitive value.
*
* @param <TLayoutType> The type of layout type.
* @param <TElement> The sub-element type of the field.
* @param path The scope-relative path of the field to write.
* @param value The value to write.
* @param type The layout type.
* @param sparse The {@link RowBuffer} access method for {@code type}.
* @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
*/
private <TLayoutType extends LayoutType<TElement[]> & LayoutListWritable<TElement>, TElement> Result writePrimitive(UtfAnyString path, ReadOnlySpan<TElement> value, TLayoutType type, AccessReadOnlySpanMethod<TElement> sparse) {
Result result = Result.NOT_FOUND; Result result = Result.NOT_FOUND;
if (this.cursor.scopeType() instanceof LayoutUDT) { if (this.cursor.scopeType() instanceof LayoutUDT) {
result = this.writeSchematizedValue(path, value); result = this.writeSchematizedValue(path, value);
@@ -778,117 +719,33 @@ public final class RowWriter {
/** /**
* Helper for writing a primitive value. * Helper for writing a primitive value.
* <typeparam name="TLayoutType">The type of layout type.</typeparam>
* <typeparam name="TElement">The sub-element type of the field.</typeparam>
* *
* @param path The scope-relative path of the field to write. * @param <TValue> The type of the primitive value.
* @param value The value to write. * @param path The scope-relative path of the field to write.
* @param type The layout type. * @param value The value to write.
* @param sparse The {@link RowBuffer} access method for <paramref name="type" />. * @param type The layout type.
* @return Success if the write is successful, an error code otherwise. * @param sparse The {@link RowBuffer} access method for {@code type}.
* @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
*/ */
private <TLayoutType extends LayoutType<TElement[]> & LayoutSpanWritable<TElement>, TElement> Result writePrimitive(UtfAnyString path, ReadOnlySpan<TElement> value, TLayoutType type, AccessReadOnlySpanMethod<TElement> sparse) { private <TValue> Result writePrimitive(
UtfAnyString path, TValue value, LayoutTypePrimitive<TValue> type, Consumer<TValue> sparse) {
Result result = Result.NOT_FOUND; Result result = Result.NOT_FOUND;
if (this.cursor.scopeType() instanceof LayoutUDT) { if (this.cursor.scopeType() instanceof LayoutUDT) {
result = this.writeSchematizedValue(path, value); result = this.writeSchematizedValue(path, value);
} }
if (result == Result.NOT_FOUND) { if (result == Result.NOT_FOUND) {
// Write sparse value.
result = this.prepareSparseWrite(path, type.typeArg()); result = this.prepareSparseWrite(path, type.typeArg());
if (result != Result.SUCCESS) { if (result != Result.SUCCESS) {
return result; return result;
} }
Reference<RowWriter> tempReference_this = sparse.accept(this, value);
new Reference<RowWriter>(this); RowCursors.moveNext(this.cursor, this.row);
// TODO: C# TO JAVA CONVERTER: The following line could not be converted:
sparse(ref this, value)
this = tempReference_this.get();
Reference<RowBuffer> tempReference_row =
new Reference<RowBuffer>(this.row);
RowCursors.moveNext(this.cursor,
tempReference_row);
this.row = tempReference_row.get();
}
return result;
}
/**
* Helper for writing a primitive value.
* <typeparam name="TLayoutType">The type of layout type.</typeparam>
* <typeparam name="TElement">The sub-element type of the field.</typeparam>
*
* @param path The scope-relative path of the field to write.
* @param value The value to write.
* @param type The layout type.
* @param sparse The {@link RowBuffer} access method for <paramref name="type" />.
* @return Success if the write is successful, an error code otherwise.
*/
private <TLayoutType extends LayoutType<TElement[]> & ILayoutSequenceWritable<TElement>, TElement> Result writePrimitive(UtfAnyString path, ReadOnlySequence<TElement> value, TLayoutType type, AccessMethod<ReadOnlySequence<TElement>> sparse) {
Result result = Result.NOT_FOUND;
if (this.cursor.scopeType() instanceof LayoutUDT) {
result = this.writeSchematizedValue(path, value);
}
if (result == Result.NOT_FOUND) {
// Write sparse value.
result = this.prepareSparseWrite(path, type.typeArg());
if (result != Result.SUCCESS) {
return result;
}
Reference<RowWriter> tempReference_this =
new Reference<RowWriter>(this);
// TODO: C# TO JAVA CONVERTER: The following line could not be converted:
sparse(ref this, value)
this = tempReference_this.get();
Reference<RowBuffer> tempReference_row =
new Reference<RowBuffer>(this.row);
RowCursors.moveNext(this.cursor,
tempReference_row);
this.row = tempReference_row.get();
}
return result;
}
/**
* Helper for writing a primitive value.
* <typeparam name="TValue">The type of the primitive value.</typeparam>
*
* @param path The scope-relative path of the field to write.
* @param value The value to write.
* @param type The layout type.
* @param sparse The {@link RowBuffer} access method for <paramref name="type" />.
* @return Success if the write is successful, an error code otherwise.
*/
private <TValue> Result writePrimitive(UtfAnyString path, TValue value, LayoutType<TValue> type,
AccessMethod<TValue> sparse) {
Result result = Result.NOT_FOUND;
if (this.cursor.scopeType() instanceof LayoutUDT) {
result = this.writeSchematizedValue(path, value);
}
if (result == Result.NOT_FOUND) {
// Write sparse value.
result = this.prepareSparseWrite(path, type.typeArg());
if (result != Result.SUCCESS) {
return result;
}
Reference<RowWriter> tempReference_this =
new Reference<RowWriter>(this);
// TODO: C# TO JAVA CONVERTER: The following line could not be converted:
sparse(ref this, value)
this = tempReference_this.get();
Reference<RowBuffer> tempReference_row =
new Reference<RowBuffer>(this.row);
RowCursors.moveNext(this.cursor,
tempReference_row);
this.row = tempReference_row.get();
} }
return result; return result;
@@ -896,11 +753,11 @@ public final class RowWriter {
/** /**
* Write a generic schematized field value via the scope's layout. * Write a generic schematized field value via the scope's layout.
* <typeparam name="TValue">The expected type of the field.</typeparam>
* *
* @param path The scope-relative path of the field to write. * @param <TValue> The expected type of the field.
* @param value The value to write. * @param path The scope-relative path of the field to write.
* @return Success if the write is successful, an error code otherwise. * @param value The value to write.
* @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
*/ */
private <TValue> Result writeSchematizedValue(UtfAnyString path, TValue value) { private <TValue> Result writeSchematizedValue(UtfAnyString path, TValue value) {
LayoutColumn col; LayoutColumn col;
@@ -943,7 +800,7 @@ public final class RowWriter {
* *
* @param path The scope-relative path of the field to write. * @param path The scope-relative path of the field to write.
* @param value The value to write. * @param value The value to write.
* @return Success if the write is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
*/ */
private Result writeSchematizedValue(UtfAnyString path, Utf8String value) { private Result writeSchematizedValue(UtfAnyString path, Utf8String value) {
LayoutColumn col; LayoutColumn col;
@@ -987,11 +844,11 @@ public final class RowWriter {
/** /**
* Write a generic schematized field value via the scope's layout. * Write a generic schematized field value via the scope's layout.
* <typeparam name="TElement">The sub-element type of the field.</typeparam> * @param <TElement> The sub-element type of the field.
* *
* @param path The scope-relative path of the field to write. * @param path The scope-relative path of the field to write.
* @param value The value to write. * @param value The value to write.
* @return Success if the write is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
*/ */
private <TElement> Result writeSchematizedValue(UtfAnyString path, ReadOnlySpan<TElement> value) { private <TElement> Result writeSchematizedValue(UtfAnyString path, ReadOnlySpan<TElement> value) {
LayoutColumn col; LayoutColumn col;
@@ -1027,11 +884,11 @@ public final class RowWriter {
/** /**
* Write a generic schematized field value via the scope's layout. * Write a generic schematized field value via the scope's layout.
* <typeparam name="TElement">The sub-element type of the field.</typeparam> * @param <TElement> The sub-element type of the field.
* *
* @param path The scope-relative path of the field to write. * @param path The scope-relative path of the field to write.
* @param value The value to write. * @param value The value to write.
* @return Success if the write is successful, an error code otherwise. * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
*/ */
private <TElement> Result writeSchematizedValue(UtfAnyString path, ReadOnlySequence<TElement> value) { private <TElement> Result writeSchematizedValue(UtfAnyString path, ReadOnlySequence<TElement> value) {
LayoutColumn col; LayoutColumn col;
@@ -1066,23 +923,22 @@ public final class RowWriter {
} }
@FunctionalInterface @FunctionalInterface
private interface AccessMethod<TValue> { private interface AccessMethod<TValue> extends Consumer<TValue> {
void invoke(Reference<RowWriter> writer, TValue value);
} }
@FunctionalInterface @FunctionalInterface
private interface AccessReadOnlySpanMethod<T> { private interface AccessReadOnlySpanMethod<T> {
void invoke(Reference<RowWriter> writer, ReadOnlySpan value); void invoke(RowWriter writer, ReadOnlySpan value);
} }
@FunctionalInterface @FunctionalInterface
private interface AccessUtf8SpanMethod { private interface AccessUtf8SpanMethod {
void invoke(Reference<RowWriter> writer, Utf8String value); void invoke(RowWriter writer, Utf8String value);
} }
/** /**
* A function to write content into a {@link RowBuffer}. * A function to write content into a {@link RowBuffer}.
* <typeparam name="TContext">The type of the context value passed by the caller.</typeparam> * @param <TContext> The type of the context value passed by the caller.
* *
* @param writer A forward-only cursor for writing content. * @param writer A forward-only cursor for writing content.
* @param typeArg The type of the current scope. * @param typeArg The type of the current scope.
@@ -1091,6 +947,6 @@ public final class RowWriter {
*/ */
@FunctionalInterface @FunctionalInterface
public interface WriterFunc<TContext> { public interface WriterFunc<TContext> {
Result invoke(Reference<RowWriter> writer, TypeArgument typeArg, TContext context); Result invoke(RowWriter writer, TypeArgument typeArg, TContext context);
} }
} }

View File

@@ -1,43 +1,43 @@
// Copyright (c) Microsoft Corporation. All rights reserved. // Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. // Licensed under the MIT License.
package com.azure.data.cosmos.serialization.hybridrow.recordio; package com.azure.data.cosmos.serialization.hybridrow.io;
public final class Segment { public final class Segment {
private String comment; private String comment;
private int length; private int length;
private String sdl; private String sdl;
public Segment(String comment, String sdl) { public Segment(String comment, String sdl) {
this.comment = comment; this.comment = comment;
this.sdl = sdl; this.sdl = sdl;
this.length = 0; this.length = 0;
} }
public String comment() { public String comment() {
return this.comment; return this.comment;
} }
public Segment comment(String value) { public Segment comment(String value) {
this.comment = value; this.comment = value;
return this; return this;
} }
public int length() { public int length() {
return this.length; return this.length;
} }
public Segment length(int value) { public Segment length(int value) {
this.length = value; this.length = value;
return this; return this;
} }
public String sdl() { public String sdl() {
return this.sdl; return this.sdl;
} }
public Segment sdl(String value) { public Segment sdl(String value) {
this.sdl = value; this.sdl = value;
return this; return this;
} }
} }

View File

@@ -18,8 +18,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
public final class LayoutBinary extends LayoutTypePrimitive<byte[]> { public final class LayoutBinary extends LayoutTypePrimitive<byte[]> {
// implements // implements
// LayoutSpanWritable<Byte>, // LayoutListWritable<Byte>,
// LayoutSpanReadable<Byte>, // LayoutListReadable<Byte>,
// ILayoutSequenceWritable<Byte> { // ILayoutSequenceWritable<Byte> {
public LayoutBinary() { public LayoutBinary() {

View File

@@ -13,7 +13,7 @@ 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.Preconditions.checkNotNull;
public final class LayoutBoolean extends LayoutType<Boolean> { public final class LayoutBoolean extends LayoutTypePrimitive<Boolean> implements ILayoutType {
public LayoutBoolean(boolean value) { public LayoutBoolean(boolean value) {
super(value ? LayoutCode.BOOLEAN : LayoutCode.BOOLEAN_FALSE, 0); super(value ? LayoutCode.BOOLEAN : LayoutCode.BOOLEAN_FALSE, 0);

View File

@@ -15,11 +15,11 @@ import java.util.List;
* *
* @param <TElement> The sub-element type to be written * @param <TElement> The sub-element type to be written
*/ */
public interface LayoutSpanReadable<TElement> extends ILayoutType { public interface LayoutListReadable<TElement> extends ILayoutType {
Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<List<TElement>> value); Result readFixedList(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<List<TElement>> value);
Result readSparse(RowBuffer buffer, RowCursor scope, Out<List<TElement>> value); Result readSparseList(RowBuffer buffer, RowCursor scope, Out<List<TElement>> value);
Result readVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<List<TElement>> value); Result readVariableList(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<List<TElement>> value);
} }

View File

@@ -14,13 +14,13 @@ import java.util.List;
* *
* @param <TElement> The sub-element type to be written * @param <TElement> The sub-element type to be written
*/ */
public interface LayoutSpanWritable<TElement> extends ILayoutType { public interface LayoutListWritable<TElement> extends ILayoutType {
Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, List<TElement> value); Result writeFixedList(RowBuffer buffer, RowCursor scope, LayoutColumn column, List<TElement> value);
Result writeSparse(RowBuffer buffer, RowCursor edit, TElement value); Result writeSparseList(RowBuffer buffer, RowCursor edit, TElement value);
Result writeSparse(RowBuffer buffer, RowCursor edit, List<TElement> value, UpdateOptions options); Result writeSparseList(RowBuffer buffer, RowCursor edit, List<TElement> value, UpdateOptions options);
Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, List<TElement> value); Result writeVariableList(RowBuffer buffer, RowCursor scope, LayoutColumn column, List<TElement> value);
} }

View File

@@ -13,7 +13,7 @@ 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 LayoutTypePrimitive<NullValue> implements ILayoutType {
public LayoutNull() { public LayoutNull() {
super(LayoutCode.NULL, 0); super(LayoutCode.NULL, 0);
@@ -36,7 +36,7 @@ public final class LayoutNull extends LayoutType<NullValue> {
@Nonnull @Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<NullValue> value) { public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<NullValue> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT); checkArgument(scope.scopeType() instanceof LayoutUDT);
value.set(NullValue.Default); value.set(NullValue.DEFAULT);
if (!buffer.readBit(scope.start(), column.nullBit())) { if (!buffer.readBit(scope.start(), column.nullBit())) {
return Result.NOT_FOUND; return Result.NOT_FOUND;
} }

View File

@@ -343,7 +343,7 @@ public abstract class LayoutType /*implements ILayoutType*/ {
* The physical layout type of the field cast to the specified type. * The physical layout type of the field cast to the specified type.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public final <T extends LayoutType> T typeAs() { public final <T extends ILayoutType> T typeAs() {
return (T)this; return (T)this;
} }

View File

@@ -13,7 +13,7 @@ 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.Preconditions.checkNotNull;
public abstract class LayoutTypePrimitive<T> extends LayoutType { public abstract class LayoutTypePrimitive<T> extends LayoutType implements ILayoutType {
/** /**
* Initializes a new instance of the {@link LayoutType<T>} class. * Initializes a new instance of the {@link LayoutType<T>} class.
* *

View File

@@ -37,9 +37,15 @@ public final class LayoutUtf8 extends LayoutTypePrimitive<String> implements Lay
@Nonnull final LayoutColumn column, @Nonnull final LayoutColumn column,
@Nonnull final Out<String> value) { @Nonnull final Out<String> 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");
Out<Utf8String> span = new Out<>(); Out<Utf8String> span = new Out<>();
Result result = this.readFixedSpan(buffer, scope, column, span); Result result = this.readFixedSpan(buffer, scope, column, span);
value.set(result == Result.SUCCESS ? span.get().toUtf16() : null); value.set(result == Result.SUCCESS ? span.get().toUtf16() : null);
return result; return result;
} }

View File

@@ -12,7 +12,7 @@ import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull; 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 be read as a {@link Utf8String}.
*/ */
public interface LayoutUtf8Readable extends ILayoutType { public interface LayoutUtf8Readable extends ILayoutType {

View File

@@ -15,7 +15,7 @@ import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutResolver;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutResolverNamespace; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutResolverNamespace;
import com.azure.data.cosmos.serialization.hybridrow.layouts.SystemSchema; import com.azure.data.cosmos.serialization.hybridrow.layouts.SystemSchema;
import com.azure.data.cosmos.serialization.hybridrow.recordio.RecordIOStream; import com.azure.data.cosmos.serialization.hybridrow.recordio.RecordIOStream;
import com.azure.data.cosmos.serialization.hybridrow.recordio.Segment; import com.azure.data.cosmos.serialization.hybridrow.io.Segment;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;

View File

@@ -80,7 +80,7 @@ public final class JsonModelRowGenerator {
new Reference<RowBuffer>(this.row); new Reference<RowBuffer>(this.row);
// 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:
Result tempVar = RowWriter.WriteBuffer(tempReference_row, value, (ref RowWriter writer, TypeArgument typeArg, Result tempVar = RowWriter.WriteBuffer(tempReference_row, value, (RowWriter RowWriter writer, TypeArgument typeArg,
HashMap<Utf8String, Object> dict) -> HashMap<Utf8String, Object> dict) ->
{ {
for ((Utf8String propPath,Object propValue) :dict) for ((Utf8String propPath,Object propValue) :dict)
@@ -113,7 +113,7 @@ public final class JsonModelRowGenerator {
private static Result JsonModelSwitch(Reference<RowWriter> writer, Utf8String path, Object value) { private static Result JsonModelSwitch(Reference<RowWriter> writer, Utf8String path, Object value) {
switch (value) { switch (value) {
case null: case null:
return writer.get().WriteNull(path); return writer.get().writeNull(path);
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# pattern variables in 'case' statements: // TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# pattern variables in 'case' statements:
//ORIGINAL LINE: case bool x: //ORIGINAL LINE: case bool x:
case case
@@ -123,12 +123,12 @@ public final class JsonModelRowGenerator {
//ORIGINAL LINE: case long x: //ORIGINAL LINE: case long x:
case case
long x: long x:
return writer.get().WriteInt64(path, x); return writer.get().writeInt64(path, x);
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# pattern variables in 'case' statements: // TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# pattern variables in 'case' statements:
//ORIGINAL LINE: case double x: //ORIGINAL LINE: case double x:
case case
double x: double x:
return writer.get().WriteFloat64(path, x); return writer.get().writeFloat64(path, x);
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# pattern variables in 'case' statements: // TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# pattern variables in 'case' statements:
//ORIGINAL LINE: case string x: //ORIGINAL LINE: case string x:
case String case String
@@ -156,7 +156,7 @@ public final class JsonModelRowGenerator {
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these // TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these
// are not converted by C# to Java Converter: // are not converted by C# to Java Converter:
return writer.get().WriteScope(path, new TypeArgument(LayoutType.Object), x, return writer.get().WriteScope(path, new TypeArgument(LayoutType.Object), x,
(ref RowWriter writer2, TypeArgument typeArg, HashMap<Utf8String, Object> dict) -> (RowWriter RowWriter writer2, TypeArgument typeArg, HashMap<Utf8String, Object> dict) ->
{ {
for ((Utf8String propPath,Object propValue) :dict) for ((Utf8String propPath,Object propValue) :dict)
{ {
@@ -172,7 +172,7 @@ public final class JsonModelRowGenerator {
//ORIGINAL LINE: case List<object> x: //ORIGINAL LINE: case List<object> x:
case ArrayList < Object > x: case ArrayList < Object > x:
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not converted by C# to Java Converter: // TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not converted by C# to Java Converter:
return writer.get().WriteScope(path, new TypeArgument(LayoutType.Array), x, (ref RowWriter writer2, TypeArgument typeArg, ArrayList<Object> list) -> return writer.get().WriteScope(path, new TypeArgument(LayoutType.Array), x, (RowWriter RowWriter writer2, TypeArgument typeArg, ArrayList<Object> list) ->
{ {
for (Object elm : list) { for (Object elm : list) {
Reference<com.azure.data.cosmos.serialization.hybridrow.io.RowWriter> tempReference_writer2 = new Reference<com.azure.data.cosmos.serialization.hybridrow.io.RowWriter>(writer2); Reference<com.azure.data.cosmos.serialization.hybridrow.io.RowWriter> tempReference_writer2 = new Reference<com.azure.data.cosmos.serialization.hybridrow.io.RowWriter>(writer2);

View File

@@ -10,7 +10,7 @@ import com.azure.data.cosmos.serialization.hybridrow.MemorySpanResizer;
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.recordio.RecordIOStream; import com.azure.data.cosmos.serialization.hybridrow.recordio.RecordIOStream;
import com.azure.data.cosmos.serialization.hybridrow.recordio.Segment; import com.azure.data.cosmos.serialization.hybridrow.io.Segment;
import java.io.Closeable; import java.io.Closeable;
import java.io.File; import java.io.File;

View File

@@ -5,7 +5,6 @@ package com.azure.data.cosmos.serialization.hybridrow.unit;
import Newtonsoft.Json.*; import Newtonsoft.Json.*;
import com.azure.data.cosmos.core.Reference; import com.azure.data.cosmos.core.Reference;
import com.azure.data.cosmos.core.Reference;
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;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor; import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
@@ -80,7 +79,7 @@ public final class CrossVersioningUnitTests {
d.LayoutCodeSwitch("array_t<utf8>", value:new String[] { "abc", "def", "hij" }) d.LayoutCodeSwitch("array_t<utf8>", value:new String[] { "abc", "def", "hij" })
d.LayoutCodeSwitch("tuple<varint,int64>", value:Tuple.Create(-6148914691236517206L, -6148914691236517206L)) d.LayoutCodeSwitch("tuple<varint,int64>", value:Tuple.Create(-6148914691236517206L, -6148914691236517206L))
d.LayoutCodeSwitch("tuple<null,tuple<int8,int8>>", value: d.LayoutCodeSwitch("tuple<null,tuple<int8,int8>>", value:
Tuple.Create(NullValue.Default, Tuple.Create((byte)-86, (byte)-86))) Tuple.Create(NullValue.DEFAULT, Tuple.Create((byte)-86, (byte)-86)))
d.LayoutCodeSwitch("tuple<bool,udt>", value:Tuple.Create(false, new Point(1, 2))) d.LayoutCodeSwitch("tuple<bool,udt>", value:Tuple.Create(false, new Point(1, 2)))
d.LayoutCodeSwitch("set_t<utf8>", value:new String[] { "abc", "efg", "xzy" }) d.LayoutCodeSwitch("set_t<utf8>", value:new String[] { "abc", "efg", "xzy" })
d.LayoutCodeSwitch("set_t<array_t<int8>>", value:new byte[][] d.LayoutCodeSwitch("set_t<array_t<int8>>", value:new byte[][]
@@ -276,7 +275,7 @@ public final class CrossVersioningUnitTests {
d.LayoutCodeSwitch("array_t<utf8>", value:new String[] { "abc", "def", "hij" }) d.LayoutCodeSwitch("array_t<utf8>", value:new String[] { "abc", "def", "hij" })
d.LayoutCodeSwitch("tuple<varint,int64>", value:Tuple.Create(-6148914691236517206L, -6148914691236517206L)) d.LayoutCodeSwitch("tuple<varint,int64>", value:Tuple.Create(-6148914691236517206L, -6148914691236517206L))
d.LayoutCodeSwitch("tuple<null,tuple<int8,int8>>", value: d.LayoutCodeSwitch("tuple<null,tuple<int8,int8>>", value:
Tuple.Create(NullValue.Default, Tuple.Create((byte)-86, (byte)-86))) Tuple.Create(NullValue.DEFAULT, Tuple.Create((byte)-86, (byte)-86)))
d.LayoutCodeSwitch("tuple<bool,udt>", value:Tuple.Create(false, new Point(1, 2))) d.LayoutCodeSwitch("tuple<bool,udt>", value:Tuple.Create(false, new Point(1, 2)))
d.LayoutCodeSwitch("set_t<utf8>", value:new String[] { "abc", "efg", "xzy" }) d.LayoutCodeSwitch("set_t<utf8>", value:new String[] { "abc", "efg", "xzy" })
d.LayoutCodeSwitch("set_t<array_t<int8>>", value:new byte[][] d.LayoutCodeSwitch("set_t<array_t<int8>>", value:new byte[][]
@@ -443,7 +442,7 @@ public final class CrossVersioningUnitTests {
d.LayoutCodeSwitch("array_t<utf8>", value:new String[] { "abc", "def", "hij" }) d.LayoutCodeSwitch("array_t<utf8>", value:new String[] { "abc", "def", "hij" })
d.LayoutCodeSwitch("tuple<varint,int64>", value:Tuple.Create(-6148914691236517206L, -6148914691236517206L)) d.LayoutCodeSwitch("tuple<varint,int64>", value:Tuple.Create(-6148914691236517206L, -6148914691236517206L))
d.LayoutCodeSwitch("tuple<null,tuple<int8,int8>>", value: d.LayoutCodeSwitch("tuple<null,tuple<int8,int8>>", value:
Tuple.Create(NullValue.Default, Tuple.Create((byte)-86, (byte)-86))) Tuple.Create(NullValue.DEFAULT, Tuple.Create((byte)-86, (byte)-86)))
d.LayoutCodeSwitch("tuple<bool,udt>", value:Tuple.Create(false, new Point(1, 2))) d.LayoutCodeSwitch("tuple<bool,udt>", value:Tuple.Create(false, new Point(1, 2)))
d.LayoutCodeSwitch("set_t<utf8>", value:new String[] { "abc", "efg", "xzy" }) d.LayoutCodeSwitch("set_t<utf8>", value:new String[] { "abc", "efg", "xzy" })
d.LayoutCodeSwitch("set_t<array_t<int8>>", value:new byte[][] d.LayoutCodeSwitch("set_t<array_t<int8>>", value:new byte[][]

View File

@@ -71,7 +71,7 @@ public class LayoutCompilerUnitTests {
RoundTripFixed.Expected tempVar = new RoundTripFixed.Expected(); RoundTripFixed.Expected tempVar = new RoundTripFixed.Expected();
tempVar.TypeName = "null"; tempVar.TypeName = "null";
tempVar.Default = new NullValue(); tempVar.Default = new NullValue();
tempVar.Value = NullValue.Default; tempVar.Value = NullValue.DEFAULT;
RoundTripFixed.Expected tempVar2 = new RoundTripFixed.Expected(); RoundTripFixed.Expected tempVar2 = new RoundTripFixed.Expected();
tempVar2.TypeName = "bool"; tempVar2.TypeName = "bool";
tempVar2.Default = false; tempVar2.Default = false;
@@ -1858,7 +1858,7 @@ private final static class RoundTripSparseArray extends TestActionDispatcher<Rou
// Overwrite the whole scope. // Overwrite the whole scope.
Reference<RowCursor> tempReference_field3 = Reference<RowCursor> tempReference_field3 =
new Reference<RowCursor>(field); new Reference<RowCursor>(field);
r = LayoutType.Null.writeSparse(row, tempReference_field3, NullValue.Default); r = LayoutType.Null.writeSparse(row, tempReference_field3, NullValue.DEFAULT);
field = tempReference_field3.get(); field = tempReference_field3.get();
ResultAssert.IsSuccess(r, tag); ResultAssert.IsSuccess(r, tag);
Reference<RowCursor> tempReference_field4 = Reference<RowCursor> tempReference_field4 =
@@ -2049,7 +2049,7 @@ private final static class RoundTripSparseObject extends TestActionDispatcher<Ro
// Overwrite the whole scope. // Overwrite the whole scope.
Reference<RowCursor> tempReference_field4 = Reference<RowCursor> tempReference_field4 =
new Reference<RowCursor>(field); new Reference<RowCursor>(field);
r = LayoutType.Null.writeSparse(row, tempReference_field4, NullValue.Default); r = LayoutType.Null.writeSparse(row, tempReference_field4, NullValue.DEFAULT);
field = tempReference_field4.get(); field = tempReference_field4.get();
ResultAssert.IsSuccess(r, "Json: {0}", expected.Json); ResultAssert.IsSuccess(r, "Json: {0}", expected.Json);
Reference<RowCursor> tempReference_field5 = Reference<RowCursor> tempReference_field5 =
@@ -2187,7 +2187,7 @@ private final static class RoundTripSparseObjectMulti extends TestActionDispatch
} else { } else {
Reference<RowCursor> tempReference_nestedField2 = Reference<RowCursor> tempReference_nestedField2 =
new Reference<RowCursor>(nestedField); new Reference<RowCursor>(nestedField);
r = LayoutType.Null.writeSparse(row, tempReference_nestedField2, NullValue.Default); r = LayoutType.Null.writeSparse(row, tempReference_nestedField2, NullValue.DEFAULT);
nestedField = tempReference_nestedField2.get(); nestedField = tempReference_nestedField2.get();
ResultAssert.IsSuccess(r, tag); ResultAssert.IsSuccess(r, tag);
} }
@@ -2260,7 +2260,7 @@ private final static class RoundTripSparseObjectMulti extends TestActionDispatch
// Overwrite the nested field. // Overwrite the nested field.
Reference<RowCursor> tempReference_nestedField4 = Reference<RowCursor> tempReference_nestedField4 =
new Reference<RowCursor>(nestedField); new Reference<RowCursor>(nestedField);
r = LayoutType.Null.writeSparse(row, tempReference_nestedField4, NullValue.Default); r = LayoutType.Null.writeSparse(row, tempReference_nestedField4, NullValue.DEFAULT);
nestedField = tempReference_nestedField4.get(); nestedField = tempReference_nestedField4.get();
ResultAssert.IsSuccess(r, tag); ResultAssert.IsSuccess(r, tag);
@@ -2381,7 +2381,7 @@ private final static class RoundTripSparseObjectNested extends TestActionDispatc
} else { } else {
Reference<RowCursor> tempReference_field2 = Reference<RowCursor> tempReference_field2 =
new Reference<RowCursor>(field); new Reference<RowCursor>(field);
r = LayoutType.Null.writeSparse(row, tempReference_field2, NullValue.Default); r = LayoutType.Null.writeSparse(row, tempReference_field2, NullValue.DEFAULT);
field = tempReference_field2.get(); field = tempReference_field2.get();
ResultAssert.IsSuccess(r, tag); ResultAssert.IsSuccess(r, tag);
} }
@@ -2517,7 +2517,7 @@ private final static class RoundTripSparseOrdering extends TestActionDispatcher<
} else { } else {
Reference<RowCursor> tempReference_field2 = Reference<RowCursor> tempReference_field2 =
new Reference<RowCursor>(field); new Reference<RowCursor>(field);
r = LayoutType.Null.writeSparse(row, tempReference_field2, NullValue.Default); r = LayoutType.Null.writeSparse(row, tempReference_field2, NullValue.DEFAULT);
field = tempReference_field2.get(); field = tempReference_field2.get();
ResultAssert.IsSuccess(r, "Json: {0}", json); ResultAssert.IsSuccess(r, "Json: {0}", json);
Out<TValue> tempOut_value3 = new Out<TValue>(); Out<TValue> tempOut_value3 = new Out<TValue>();
@@ -2835,7 +2835,7 @@ private final static class RoundTripSparseSet extends TestActionDispatcher<Round
// Overwrite the whole scope. // Overwrite the whole scope.
Reference<RowCursor> tempReference_field9 = new Reference<RowCursor>(field); Reference<RowCursor> tempReference_field9 = new Reference<RowCursor>(field);
r = LayoutType.Null.writeSparse(row, tempReference_field9, NullValue.Default); r = LayoutType.Null.writeSparse(row, tempReference_field9, NullValue.DEFAULT);
field = tempReference_field9.get(); field = tempReference_field9.get();
ResultAssert.IsSuccess(r, tag); ResultAssert.IsSuccess(r, tag);
Reference<RowCursor> tempReference_field10 = new Reference<RowCursor>(field); Reference<RowCursor> tempReference_field10 = new Reference<RowCursor>(field);
@@ -2982,7 +2982,7 @@ private final static class RoundTripSparseSimple extends TestActionDispatcher<Ro
} else { } else {
Reference<RowCursor> tempReference_field2 = Reference<RowCursor> tempReference_field2 =
new Reference<RowCursor>(field); new Reference<RowCursor>(field);
r = LayoutType.Null.writeSparse(row, tempReference_field2, NullValue.Default); r = LayoutType.Null.writeSparse(row, tempReference_field2, NullValue.DEFAULT);
field = tempReference_field2.get(); field = tempReference_field2.get();
ResultAssert.IsSuccess(r, "Json: {0}", expected.Json); ResultAssert.IsSuccess(r, "Json: {0}", expected.Json);
// 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

View File

@@ -11,7 +11,7 @@ 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.io.RowReader; import com.azure.data.cosmos.serialization.hybridrow.io.RowReader;
import com.azure.data.cosmos.serialization.hybridrow.recordio.RecordIOStream; import com.azure.data.cosmos.serialization.hybridrow.recordio.RecordIOStream;
import com.azure.data.cosmos.serialization.hybridrow.recordio.Segment; import com.azure.data.cosmos.serialization.hybridrow.io.Segment;
import com.azure.data.cosmos.serialization.hybridrow.unit.customerschema.Address; import com.azure.data.cosmos.serialization.hybridrow.unit.customerschema.Address;
import java.nio.file.Files; import java.nio.file.Files;

View File

@@ -174,7 +174,7 @@ public final class RowOperationDispatcher {
switch (type.LayoutCode) { switch (type.LayoutCode) {
case Null: case Null:
Reference<RowOperationDispatcher> tempReference_this = new Reference<RowOperationDispatcher>(this); Reference<RowOperationDispatcher> tempReference_this = new Reference<RowOperationDispatcher>(this);
this.dispatcher.<LayoutNull, NullValue>Dispatch(tempReference_this, scope, col, type, NullValue.Default); this.dispatcher.<LayoutNull, NullValue>Dispatch(tempReference_this, scope, col, type, NullValue.DEFAULT);
this = tempReference_this.get(); this = tempReference_this.get();
break; break;
case Boolean: case Boolean:

View File

@@ -136,7 +136,7 @@ public final class RowReaderUnitTests {
d.LayoutCodeSwitch("array_t<utf8>", value:new String[] { "abc", "def", "hij" }) d.LayoutCodeSwitch("array_t<utf8>", value:new String[] { "abc", "def", "hij" })
d.LayoutCodeSwitch("tuple<varint,int64>", value:Tuple.Create(-6148914691236517206L, -6148914691236517206L)) d.LayoutCodeSwitch("tuple<varint,int64>", value:Tuple.Create(-6148914691236517206L, -6148914691236517206L))
d.LayoutCodeSwitch("tuple<null,tuple<int8,int8>>", value: d.LayoutCodeSwitch("tuple<null,tuple<int8,int8>>", value:
Tuple.Create(NullValue.Default, Tuple.Create((byte)-86, (byte)-86))) Tuple.Create(NullValue.DEFAULT, Tuple.Create((byte)-86, (byte)-86)))
d.LayoutCodeSwitch("tuple<bool,udt>", value:Tuple.Create(false, new Point(1, 2))) d.LayoutCodeSwitch("tuple<bool,udt>", value:Tuple.Create(false, new Point(1, 2)))
d.LayoutCodeSwitch("nullable<int32,int64>", value:Tuple.Create(null, (Long)123L)) d.LayoutCodeSwitch("nullable<int32,int64>", value:Tuple.Create(null, (Long)123L))
//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:

View File

@@ -57,7 +57,7 @@ public final class RowWriterUnitTests {
new Reference<RowBuffer>(row); new Reference<RowBuffer>(row);
// 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:
ResultAssert.IsSuccess(RowWriter.WriteBuffer(tempReference_row, null, (ref RowWriter writer, ResultAssert.IsSuccess(RowWriter.WriteBuffer(tempReference_row, null, (RowWriter RowWriter writer,
TypeArgument rootTypeArg, Object ignored) -> TypeArgument rootTypeArg, Object ignored) ->
{ {
ResultAssert.IsSuccess(writer.WriteNull("null")); ResultAssert.IsSuccess(writer.WriteNull("null"));
@@ -198,7 +198,7 @@ public final class RowWriterUnitTests {
assert layout.TryFind("tuple<null,tuple<int8,int8>>", tempOut_col5); assert layout.TryFind("tuple<null,tuple<int8,int8>>", tempOut_col5);
col = tempOut_col5.get(); col = tempOut_col5.get();
ResultAssert.IsSuccess(writer.WriteScope(col.path(), col.typeArg().clone(), ResultAssert.IsSuccess(writer.WriteScope(col.path(), col.typeArg().clone(),
Tuple.Create(NullValue.Default, Tuple.Create((byte)-86, (byte)-86)), (ref RowWriter writer2, Tuple.Create(NullValue.DEFAULT, Tuple.Create((byte)-86, (byte)-86)), (ref RowWriter writer2,
TypeArgument typeArg, TypeArgument typeArg,
Tuple<NullValue, Tuple<Byte, Tuple<NullValue, Tuple<Byte,
Byte>> values) -> Byte>> values) ->
@@ -240,20 +240,20 @@ public final class RowWriterUnitTests {
ResultAssert.IsSuccess(writer.WriteScope(col.path(), col.typeArg().clone(), Tuple.Create(null, ResultAssert.IsSuccess(writer.WriteScope(col.path(), col.typeArg().clone(), Tuple.Create(null,
(Long)123L), (ref RowWriter writer2, TypeArgument typeArg, Tuple<Integer, Long> values) -> (Long)123L), (ref RowWriter writer2, TypeArgument typeArg, Tuple<Integer, Long> values) ->
{ {
RowWriter.WriterFunc<Integer> f0 = (Reference<RowWriter> writer, TypeArgument typeArg, RowWriter.WriterFunc<Integer> f0 = (com.azure.data.cosmos.serialization.hybridrow.io.RowWriter writer, TypeArgument typeArg,
Integer context) -> null.invoke(writer, typeArg.clone(), context); Integer context) -> null.invoke(writer, typeArg.clone(), context);
if (values.Item1 != null) { if (values.Item1 != null) {
f0 = (ref RowWriter writer3, TypeArgument typeArg2, Integer value) -> writer3.WriteInt32(null, f0 = (com.azure.data.cosmos.serialization.hybridrow.io.RowWriter RowWriter writer3, TypeArgument typeArg2, Integer value) -> writer3.WriteInt32(null,
value.intValue()); value.intValue());
} }
ResultAssert.IsSuccess(writer2.WriteScope(null, typeArg.getTypeArgs().get(0).clone(), values.Item1, ResultAssert.IsSuccess(writer2.WriteScope(null, typeArg.getTypeArgs().get(0).clone(), values.Item1,
f0)); f0));
RowWriter.WriterFunc<Long> f1 = (Reference<RowWriter> writer, TypeArgument typeArg, RowWriter.WriterFunc<Long> f1 = (com.azure.data.cosmos.serialization.hybridrow.io.RowWriter writer, TypeArgument typeArg,
Long context) -> null.invoke(writer, typeArg.clone(), context); Long context) -> null.invoke(writer, typeArg.clone(), context);
if (values.Item2 != null) { if (values.Item2 != null) {
f1 = (ref RowWriter writer3, TypeArgument typeArg2, Long value) -> writer3.WriteInt64(null, f1 = (com.azure.data.cosmos.serialization.hybridrow.io.RowWriter RowWriter writer3, TypeArgument typeArg2, Long value) -> writer3.WriteInt64(null,
value.longValue()); value.longValue());
} }

View File

@@ -175,7 +175,7 @@ public final class SerializerUnitTest {
break; break;
case "resourcePath": case "resourcePath":
Out<String> tempOut_ResourcePath = new Out<String>(); Out<String> tempOut_ResourcePath = new Out<String>();
r = reader.get().readString(tempOut_ResourcePath); r = reader.get().readUtf8String(tempOut_ResourcePath);
retval.ResourcePath = tempOut_ResourcePath.get(); retval.ResourcePath = tempOut_ResourcePath.get();
if (r != Result.SUCCESS) { if (r != Result.SUCCESS) {
return r; return r;

View File

@@ -17,7 +17,7 @@ public final class AddressSerializer {
switch (reader.get().path()) { switch (reader.get().path()) {
case "street": case "street":
Out<String> tempOut_Street = new Out<String>(); Out<String> tempOut_Street = new Out<String>();
r = reader.get().readString(tempOut_Street); r = reader.get().readUtf8String(tempOut_Street);
obj.get().argValue.Street = tempOut_Street.get(); obj.get().argValue.Street = tempOut_Street.get();
if (r != Result.SUCCESS) { if (r != Result.SUCCESS) {
return r; return r;
@@ -26,7 +26,7 @@ public final class AddressSerializer {
break; break;
case "city": case "city":
Out<String> tempOut_City = new Out<String>(); Out<String> tempOut_City = new Out<String>();
r = reader.get().readString(tempOut_City); r = reader.get().readUtf8String(tempOut_City);
obj.get().argValue.City = tempOut_City.get(); obj.get().argValue.City = tempOut_City.get();
if (r != Result.SUCCESS) { if (r != Result.SUCCESS) {
return r; return r;
@@ -35,7 +35,7 @@ public final class AddressSerializer {
break; break;
case "state": case "state":
Out<String> tempOut_State = new Out<String>(); Out<String> tempOut_State = new Out<String>();
r = reader.get().readString(tempOut_State); r = reader.get().readUtf8String(tempOut_State);
obj.get().argValue.State = tempOut_State.get(); obj.get().argValue.State = tempOut_State.get();
if (r != Result.SUCCESS) { if (r != Result.SUCCESS) {
return r; return r;

View File

@@ -60,7 +60,7 @@ public final class PostalCodeSerializer {
} }
if (obj.Plus4.HasValue) { if (obj.Plus4.HasValue) {
r = writer.get().WriteInt16("plus4", obj.Plus4.Value); r = writer.get().writeInt16("plus4", obj.Plus4.Value);
return r; return r;
} }