mirror of
https://github.com/microsoft/HybridRow.git
synced 2026-01-20 01:43:20 +00:00
Progressed on port from dotnet to java
This commit is contained in:
@@ -1,37 +1,37 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
package com.azure.data.cosmos.serialization.hybridrow.recordio;
|
||||
|
||||
public final class Record {
|
||||
|
||||
public static Record empty() {
|
||||
return new Record(0, 0);
|
||||
}
|
||||
|
||||
private int crc32;
|
||||
private int length;
|
||||
|
||||
public Record(int length, int crc32) {
|
||||
this.length = length;
|
||||
this.crc32 = crc32;
|
||||
}
|
||||
|
||||
public int crc32() {
|
||||
return this.crc32;
|
||||
}
|
||||
|
||||
public Record crc32(int value) {
|
||||
this.crc32 = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int length() {
|
||||
return this.length;
|
||||
}
|
||||
|
||||
public Record length(int value) {
|
||||
this.length = value;
|
||||
return this;
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
package com.azure.data.cosmos.serialization.hybridrow.recordio;
|
||||
|
||||
public final class Record {
|
||||
|
||||
public static Record empty() {
|
||||
return new Record(0, 0);
|
||||
}
|
||||
|
||||
private int crc32;
|
||||
private int length;
|
||||
|
||||
public Record(int length, int crc32) {
|
||||
this.length = length;
|
||||
this.crc32 = crc32;
|
||||
}
|
||||
|
||||
public int crc32() {
|
||||
return this.crc32;
|
||||
}
|
||||
|
||||
public Record crc32(int value) {
|
||||
this.crc32 = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int length() {
|
||||
return this.length;
|
||||
}
|
||||
|
||||
public Record length(int value) {
|
||||
this.length = value;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,78 +1,78 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
package com.azure.data.cosmos.serialization.hybridrow.recordio;
|
||||
|
||||
import com.azure.data.cosmos.core.Out;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.HybridRowHeader;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.ISpanResizer;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.Result;
|
||||
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.SystemSchema;
|
||||
|
||||
public final class RecordIOFormatter {
|
||||
|
||||
public static final Layout RECORD_LAYOUT = SystemSchema.layoutResolver.resolve(SystemSchema.RECORD_SCHEMA_ID);
|
||||
public static final Layout SEGMENT_LAYOUT = SystemSchema.layoutResolver.resolve(SystemSchema.SEGMENT_SCHEMA_ID);
|
||||
|
||||
public static Result FormatRecord(ReadOnlyMemory<Byte> body, Out<RowBuffer> row) {
|
||||
return FormatRecord(body, row, null);
|
||||
}
|
||||
|
||||
//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,
|
||||
// ISpanResizer<byte> resizer = default)
|
||||
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||
public static Result FormatRecord(ReadOnlyMemory<Byte> body, Out<RowBuffer> row,
|
||||
ISpanResizer<Byte> resizer) {
|
||||
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||
//ORIGINAL LINE: resizer = resizer != null ? resizer : DefaultSpanResizer<byte>.Default;
|
||||
resizer = resizer != null ? resizer : DefaultSpanResizer < Byte >.Default;
|
||||
int estimatedSize = HybridRowHeader.BYTES + RecordIOFormatter.RECORD_LAYOUT.getSize() + body.Length;
|
||||
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||
//ORIGINAL LINE: uint crc32 = Crc32.Update(0, body.Span);
|
||||
int crc32 = Crc32.Update(0, body.Span);
|
||||
Record record = new Record(body.Length, crc32);
|
||||
return RecordIOFormatter.FormatObject(resizer, estimatedSize, RecordIOFormatter.RECORD_LAYOUT, record.clone(),
|
||||
RecordSerializer.Write, row.clone());
|
||||
}
|
||||
|
||||
public static Result FormatSegment(Segment segment, Out<RowBuffer> row) {
|
||||
return FormatSegment(segment, row, null);
|
||||
}
|
||||
|
||||
//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>
|
||||
// resizer = default)
|
||||
//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) {
|
||||
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||
//ORIGINAL LINE: resizer = resizer != null ? resizer : DefaultSpanResizer<byte>.Default;
|
||||
resizer = resizer != null ? resizer : DefaultSpanResizer < Byte >.Default;
|
||||
int estimatedSize =
|
||||
HybridRowHeader.BYTES + RecordIOFormatter.SEGMENT_LAYOUT.getSize() + segment.comment() == null ? null :
|
||||
segment.comment().length() != null ? segment.comment().length() : 0 + segment.sdl() == null ? null :
|
||||
segment.sdl().length() != null ? segment.sdl().length() : 0 + 20;
|
||||
|
||||
return RecordIOFormatter.FormatObject(resizer, estimatedSize, RecordIOFormatter.SEGMENT_LAYOUT,
|
||||
segment.clone(), SegmentSerializer.Write, row.clone());
|
||||
}
|
||||
|
||||
//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
|
||||
// layout, T obj, RowWriter.WriterFunc<T> writer, out RowBuffer row)
|
||||
private static <T> Result FormatObject(ISpanResizer<Byte> resizer, int initialCapacity, Layout layout, T obj,
|
||||
RowWriter.WriterFunc<T> writer, Out<RowBuffer> row) {
|
||||
row.setAndGet(new RowBuffer(initialCapacity, resizer));
|
||||
row.get().initLayout(HybridRowVersion.V1, layout, SystemSchema.layoutResolver);
|
||||
Result r = RowWriter.WriteBuffer(row.clone(), obj, writer);
|
||||
if (r != Result.SUCCESS) {
|
||||
row.setAndGet(null);
|
||||
return r;
|
||||
}
|
||||
|
||||
return Result.SUCCESS;
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
package com.azure.data.cosmos.serialization.hybridrow.recordio;
|
||||
|
||||
import com.azure.data.cosmos.core.Out;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.HybridRowHeader;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.ISpanResizer;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.Result;
|
||||
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.SystemSchema;
|
||||
|
||||
public final class RecordIOFormatter {
|
||||
|
||||
public static final Layout RECORD_LAYOUT = SystemSchema.layoutResolver.resolve(SystemSchema.RECORD_SCHEMA_ID);
|
||||
public static final Layout SEGMENT_LAYOUT = SystemSchema.layoutResolver.resolve(SystemSchema.SEGMENT_SCHEMA_ID);
|
||||
|
||||
public static Result FormatRecord(ReadOnlyMemory<Byte> body, Out<RowBuffer> row) {
|
||||
return FormatRecord(body, row, null);
|
||||
}
|
||||
|
||||
//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,
|
||||
// ISpanResizer<byte> resizer = default)
|
||||
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||
public static Result FormatRecord(ReadOnlyMemory<Byte> body, Out<RowBuffer> row,
|
||||
ISpanResizer<Byte> resizer) {
|
||||
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||
//ORIGINAL LINE: resizer = resizer != null ? resizer : DefaultSpanResizer<byte>.Default;
|
||||
resizer = resizer != null ? resizer : DefaultSpanResizer < Byte >.Default;
|
||||
int estimatedSize = HybridRowHeader.BYTES + RecordIOFormatter.RECORD_LAYOUT.getSize() + body.Length;
|
||||
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||
//ORIGINAL LINE: uint crc32 = Crc32.Update(0, body.Span);
|
||||
int crc32 = Crc32.Update(0, body.Span);
|
||||
Record record = new Record(body.Length, crc32);
|
||||
return RecordIOFormatter.FormatObject(resizer, estimatedSize, RecordIOFormatter.RECORD_LAYOUT, record.clone(),
|
||||
RecordSerializer.Write, row.clone());
|
||||
}
|
||||
|
||||
public static Result FormatSegment(Segment segment, Out<RowBuffer> row) {
|
||||
return FormatSegment(segment, row, null);
|
||||
}
|
||||
|
||||
//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>
|
||||
// resizer = default)
|
||||
//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) {
|
||||
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||
//ORIGINAL LINE: resizer = resizer != null ? resizer : DefaultSpanResizer<byte>.Default;
|
||||
resizer = resizer != null ? resizer : DefaultSpanResizer < Byte >.Default;
|
||||
int estimatedSize =
|
||||
HybridRowHeader.BYTES + RecordIOFormatter.SEGMENT_LAYOUT.getSize() + segment.comment() == null ? null :
|
||||
segment.comment().length() != null ? segment.comment().length() : 0 + segment.sdl() == null ? null :
|
||||
segment.sdl().length() != null ? segment.sdl().length() : 0 + 20;
|
||||
|
||||
return RecordIOFormatter.FormatObject(resizer, estimatedSize, RecordIOFormatter.SEGMENT_LAYOUT,
|
||||
segment.clone(), SegmentSerializer.Write, row.clone());
|
||||
}
|
||||
|
||||
//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
|
||||
// layout, T obj, RowWriter.WriterFunc<T> writer, out RowBuffer row)
|
||||
private static <T> Result FormatObject(ISpanResizer<Byte> resizer, int initialCapacity, Layout layout, T obj,
|
||||
RowWriter.WriterFunc<T> writer, Out<RowBuffer> row) {
|
||||
row.setAndGet(new RowBuffer(initialCapacity, resizer));
|
||||
row.get().initLayout(HybridRowVersion.V1, layout, SystemSchema.layoutResolver);
|
||||
Result r = RowWriter.WriteBuffer(row.clone(), obj, writer);
|
||||
if (r != Result.SUCCESS) {
|
||||
row.setAndGet(null);
|
||||
return r;
|
||||
}
|
||||
|
||||
return Result.SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -1,353 +1,354 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
package com.azure.data.cosmos.serialization.hybridrow.recordio;
|
||||
|
||||
import com.azure.data.cosmos.core.Out;
|
||||
import com.azure.data.cosmos.core.Reference;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.HybridRowHeader;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.Result;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.SchemaId;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.io.RowReader;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.layouts.SystemSchema;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import it.unimi.dsi.fastutil.bytes.Byte2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.bytes.Byte2ObjectOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
public final class RecordIOParser {
|
||||
|
||||
private Record record;
|
||||
private Segment segment;
|
||||
private State state = State.values()[0];
|
||||
|
||||
/**
|
||||
* 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 record If non-empty, then the body of the next record in the sequence
|
||||
* @param need The smallest number of bytes needed to advanced the parser state further
|
||||
* <p>
|
||||
* It is recommended that this method not be called again until at least this number of bytes are
|
||||
* available.
|
||||
* @param consumed The number of bytes consumed from the input buffer
|
||||
* <p>
|
||||
* This number may be less than the total buffer size if the parser moved to a new state.
|
||||
* @return {@link Result#SUCCESS} if no error has occurred;, otherwise the {@link Result} of the last error
|
||||
* encountered during parsing.
|
||||
* <p>
|
||||
* >
|
||||
*/
|
||||
@Nonnull
|
||||
public Result process(
|
||||
@Nonnull final ByteBuf buffer,
|
||||
@Nonnull final Out<ProductionType> type,
|
||||
@Nonnull final Out<ByteBuf> record,
|
||||
@Nonnull final Out<Integer> need,
|
||||
@Nonnull final Out<Integer> consumed) {
|
||||
|
||||
Result result = Result.FAILURE;
|
||||
type.set(ProductionType.NONE);
|
||||
record.set(null);
|
||||
|
||||
final int start = buffer.readerIndex();
|
||||
|
||||
switch (this.state) {
|
||||
|
||||
case STATE:
|
||||
this.state = State.NEED_SEGMENT_LENGTH;
|
||||
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
|
||||
// goto case State.NeedSegmentLength;
|
||||
|
||||
case NEED_SEGMENT_LENGTH: {
|
||||
|
||||
final int minimalSegmentRowSize = HybridRowHeader.BYTES + RecordIOFormatter.SEGMENT_LAYOUT.size();
|
||||
|
||||
if (buffer.readableBytes() < minimalSegmentRowSize) {
|
||||
consumed.set(buffer.readerIndex() - start);
|
||||
need.set(minimalSegmentRowSize);
|
||||
return Result.INSUFFICIENT_BUFFER;
|
||||
}
|
||||
|
||||
ByteBuf span = buffer.slice(buffer.readerIndex(), minimalSegmentRowSize);
|
||||
RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.layoutResolver);
|
||||
Reference<RowBuffer> tempReference_row =
|
||||
new Reference<RowBuffer>(row);
|
||||
RowReader reader = new RowReader(tempReference_row);
|
||||
row = tempReference_row.get();
|
||||
Reference<RowReader> tempReference_reader =
|
||||
new Reference<RowReader>(reader);
|
||||
Out<Segment> tempOut_segment =
|
||||
new Out<Segment>();
|
||||
result = SegmentSerializer.read(tempReference_reader, tempOut_segment);
|
||||
this.segment = tempOut_segment.get();
|
||||
reader = tempReference_reader.get();
|
||||
if (result != Result.SUCCESS) {
|
||||
break;
|
||||
}
|
||||
|
||||
this.state = 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()) {
|
||||
need.set(this.segment.length());
|
||||
consumed.set(buffer.Length - buffer.Length);
|
||||
return Result.INSUFFICIENT_BUFFER;
|
||||
}
|
||||
|
||||
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||
//ORIGINAL LINE: Span<byte> span = b.Span.Slice(0, this.segment.Length);
|
||||
Span<Byte> span = buffer.Span.Slice(0, this.segment.length());
|
||||
RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.layoutResolver);
|
||||
Reference<RowBuffer> tempReference_row2 =
|
||||
new Reference<RowBuffer>(row);
|
||||
RowReader reader = new RowReader(tempReference_row2);
|
||||
row = tempReference_row2.get();
|
||||
Reference<RowReader> tempReference_reader2 =
|
||||
new Reference<RowReader>(reader);
|
||||
Out<Segment> tempOut_segment2
|
||||
= new Out<Segment>();
|
||||
result = SegmentSerializer.read(tempReference_reader2, tempOut_segment2);
|
||||
this.segment = tempOut_segment2.get();
|
||||
reader = tempReference_reader2.get();
|
||||
if (result != Result.SUCCESS) {
|
||||
break;
|
||||
}
|
||||
|
||||
record.set(buffer.Slice(0, span.Length));
|
||||
buffer = buffer.Slice(span.Length);
|
||||
need.set(0);
|
||||
this.state = State.NEED_HEADER;
|
||||
consumed.set(buffer.Length - buffer.Length);
|
||||
type.set(ProductionType.SEGMENT);
|
||||
return Result.SUCCESS;
|
||||
}
|
||||
|
||||
case NEED_HEADER: {
|
||||
if (buffer.Length < HybridRowHeader.BYTES) {
|
||||
need.set(HybridRowHeader.BYTES);
|
||||
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 -
|
||||
// these cannot be converted using the 'Out' helper class unless the method is within the code
|
||||
// being modified:
|
||||
MemoryMarshal.TryRead(buffer.Span, out header);
|
||||
if (header.Version != HybridRowVersion.V1) {
|
||||
result = Result.INVALID_ROW;
|
||||
break;
|
||||
}
|
||||
|
||||
if (SchemaId.opEquals(header.SchemaId,
|
||||
SystemSchema.SEGMENT_SCHEMA_ID)) {
|
||||
// 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)) {
|
||||
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
|
||||
goto case State.NEED_RECORD
|
||||
}
|
||||
|
||||
result = Result.INVALID_ROW;
|
||||
break;
|
||||
}
|
||||
|
||||
case NEED_RECORD: {
|
||||
int minimalRecordRowSize = HybridRowHeader.BYTES + RecordIOFormatter.RECORD_LAYOUT.size();
|
||||
if (buffer.Length < minimalRecordRowSize) {
|
||||
need.set(minimalRecordRowSize);
|
||||
consumed.set(buffer.Length - buffer.Length);
|
||||
return Result.INSUFFICIENT_BUFFER;
|
||||
}
|
||||
|
||||
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||
//ORIGINAL LINE: Span<byte> span = b.Span.Slice(0, minimalRecordRowSize);
|
||||
Span<Byte> span = buffer.Span.Slice(0, minimalRecordRowSize);
|
||||
RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.layoutResolver);
|
||||
Reference<RowBuffer> tempReference_row3 =
|
||||
new Reference<RowBuffer>(row);
|
||||
RowReader reader = new RowReader(tempReference_row3);
|
||||
row = tempReference_row3.get();
|
||||
Reference<RowReader> tempReference_reader3 = new Reference<RowReader>(reader);
|
||||
Out<Record> tempOut_record = new Out<Record>();
|
||||
result = RecordSerializer.read(tempReference_reader3, tempOut_record);
|
||||
this.record = tempOut_record.get();
|
||||
reader = tempReference_reader3.get();
|
||||
if (result != Result.SUCCESS) {
|
||||
break;
|
||||
}
|
||||
|
||||
buffer = buffer.Slice(span.Length);
|
||||
this.state = 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()) {
|
||||
need.set(this.record.length());
|
||||
consumed.set(buffer.Length - buffer.Length);
|
||||
return Result.INSUFFICIENT_BUFFER;
|
||||
}
|
||||
|
||||
record.set(buffer.Slice(0, this.record.length()));
|
||||
|
||||
// Validate that the record has not been corrupted.
|
||||
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||
//ORIGINAL LINE: uint crc32 = Crc32.Update(0, record.Span);
|
||||
int crc32 = Crc32.Update(0, record.get().Span);
|
||||
if (crc32 != this.record.crc32()) {
|
||||
result = Result.INVALID_ROW;
|
||||
break;
|
||||
}
|
||||
|
||||
buffer = buffer.Slice(this.record.length());
|
||||
need.set(0);
|
||||
this.state = State.NEED_HEADER;
|
||||
consumed.set(buffer.Length - buffer.Length);
|
||||
type.set(ProductionType.RECORD);
|
||||
return Result.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
this.state = State.ERROR;
|
||||
need.set(0);
|
||||
consumed.set(buffer.Length - buffer.Length);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* True if a valid segment has been parsed.
|
||||
*/
|
||||
public boolean haveSegment() {
|
||||
return this.state.value() >= State.NEED_HEADER.value();
|
||||
}
|
||||
|
||||
/**
|
||||
* If a valid segment has been parsed then current active segment, otherwise undefined.
|
||||
*/
|
||||
public Segment segment() {
|
||||
checkState(this.haveSegment());
|
||||
return this.segment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes the type of Hybrid Rows produced by the parser.
|
||||
*/
|
||||
public enum ProductionType {
|
||||
/**
|
||||
* No hybrid row was produced. The parser needs more data.
|
||||
*/
|
||||
NONE(0),
|
||||
|
||||
/**
|
||||
* A new segment row was produced.
|
||||
*/
|
||||
SEGMENT(1),
|
||||
|
||||
/**
|
||||
* A record in the current segment was produced.
|
||||
*/
|
||||
RECORD(2);
|
||||
|
||||
public static final int BYTES = Integer.BYTES;
|
||||
|
||||
private static Int2ObjectMap<ProductionType> mappings;
|
||||
private int value;
|
||||
|
||||
ProductionType(int value) {
|
||||
this.value = value;
|
||||
mappings().put(value, this);
|
||||
}
|
||||
|
||||
public int value() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public static ProductionType from(int value) {
|
||||
return mappings().get(value);
|
||||
}
|
||||
|
||||
private static Int2ObjectMap<ProductionType> mappings() {
|
||||
if (mappings == null) {
|
||||
synchronized (ProductionType.class) {
|
||||
if (mappings == null) {
|
||||
mappings = new Int2ObjectOpenHashMap<>();
|
||||
}
|
||||
}
|
||||
}
|
||||
return mappings;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The states for the internal state machine.
|
||||
* Note: numerical ordering of these states matters.
|
||||
*/
|
||||
private enum State {
|
||||
STATE(
|
||||
(byte) 0, "Start: no buffers have yet been provided to the parser"),
|
||||
ERROR(
|
||||
(byte) 1, "Unrecoverable parse error encountered"),
|
||||
NEED_SEGMENT_LENGTH(
|
||||
(byte) 2, "Parsing segment header length"),
|
||||
NEED_SEGMENT(
|
||||
(byte) 3, "Parsing segment header"),
|
||||
NEED_HEADER(
|
||||
(byte) 4, "Parsing HybridRow header"),
|
||||
NEED_RECORD(
|
||||
(byte) 5, "Parsing record header"),
|
||||
NEED_ROW(
|
||||
(byte) 6, "Parsing row body");
|
||||
|
||||
public static final int BYTES = Byte.SIZE;
|
||||
|
||||
private static Byte2ObjectMap<State> mappings;
|
||||
private final String description;
|
||||
private final byte value;
|
||||
|
||||
State(byte value, String description) {
|
||||
this.description = description;
|
||||
this.value = value;
|
||||
mappings().put(value, this);
|
||||
}
|
||||
|
||||
public String description() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public byte value() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public static State from(byte value) {
|
||||
return mappings().get(value);
|
||||
}
|
||||
|
||||
private static Byte2ObjectMap<State> mappings() {
|
||||
if (mappings == null) {
|
||||
synchronized (State.class) {
|
||||
if (mappings == null) {
|
||||
mappings = new Byte2ObjectOpenHashMap<>();
|
||||
}
|
||||
}
|
||||
}
|
||||
return mappings;
|
||||
}
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
package com.azure.data.cosmos.serialization.hybridrow.recordio;
|
||||
|
||||
import com.azure.data.cosmos.core.Out;
|
||||
import com.azure.data.cosmos.core.Reference;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.HybridRowHeader;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.Result;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.SchemaId;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.io.RowReader;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.io.Segment;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.layouts.SystemSchema;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import it.unimi.dsi.fastutil.bytes.Byte2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.bytes.Byte2ObjectOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
public final class RecordIOParser {
|
||||
|
||||
private Record record;
|
||||
private Segment segment;
|
||||
private State state = State.values()[0];
|
||||
|
||||
/**
|
||||
* 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 record If non-empty, then the body of the next record in the sequence
|
||||
* @param need The smallest number of bytes needed to advanced the parser state further
|
||||
* <p>
|
||||
* It is recommended that this method not be called again until at least this number of bytes are
|
||||
* available.
|
||||
* @param consumed The number of bytes consumed from the input buffer
|
||||
* <p>
|
||||
* This number may be less than the total buffer size if the parser moved to a new state.
|
||||
* @return {@link Result#SUCCESS} if no error has occurred;, otherwise the {@link Result} of the last error
|
||||
* encountered during parsing.
|
||||
* <p>
|
||||
* >
|
||||
*/
|
||||
@Nonnull
|
||||
public Result process(
|
||||
@Nonnull final ByteBuf buffer,
|
||||
@Nonnull final Out<ProductionType> type,
|
||||
@Nonnull final Out<ByteBuf> record,
|
||||
@Nonnull final Out<Integer> need,
|
||||
@Nonnull final Out<Integer> consumed) {
|
||||
|
||||
Result result = Result.FAILURE;
|
||||
type.set(ProductionType.NONE);
|
||||
record.set(null);
|
||||
|
||||
final int start = buffer.readerIndex();
|
||||
|
||||
switch (this.state) {
|
||||
|
||||
case STATE:
|
||||
this.state = State.NEED_SEGMENT_LENGTH;
|
||||
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
|
||||
// goto case State.NeedSegmentLength;
|
||||
|
||||
case NEED_SEGMENT_LENGTH: {
|
||||
|
||||
final int minimalSegmentRowSize = HybridRowHeader.BYTES + RecordIOFormatter.SEGMENT_LAYOUT.size();
|
||||
|
||||
if (buffer.readableBytes() < minimalSegmentRowSize) {
|
||||
consumed.set(buffer.readerIndex() - start);
|
||||
need.set(minimalSegmentRowSize);
|
||||
return Result.INSUFFICIENT_BUFFER;
|
||||
}
|
||||
|
||||
ByteBuf span = buffer.slice(buffer.readerIndex(), minimalSegmentRowSize);
|
||||
RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.layoutResolver);
|
||||
Reference<RowBuffer> tempReference_row =
|
||||
new Reference<RowBuffer>(row);
|
||||
RowReader reader = new RowReader(tempReference_row);
|
||||
row = tempReference_row.get();
|
||||
Reference<RowReader> tempReference_reader =
|
||||
new Reference<RowReader>(reader);
|
||||
Out<Segment> tempOut_segment =
|
||||
new Out<Segment>();
|
||||
result = SegmentSerializer.read(tempReference_reader, tempOut_segment);
|
||||
this.segment = tempOut_segment.get();
|
||||
reader = tempReference_reader.get();
|
||||
if (result != Result.SUCCESS) {
|
||||
break;
|
||||
}
|
||||
|
||||
this.state = 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()) {
|
||||
need.set(this.segment.length());
|
||||
consumed.set(buffer.Length - buffer.Length);
|
||||
return Result.INSUFFICIENT_BUFFER;
|
||||
}
|
||||
|
||||
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||
//ORIGINAL LINE: Span<byte> span = b.Span.Slice(0, this.segment.Length);
|
||||
Span<Byte> span = buffer.Span.Slice(0, this.segment.length());
|
||||
RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.layoutResolver);
|
||||
Reference<RowBuffer> tempReference_row2 =
|
||||
new Reference<RowBuffer>(row);
|
||||
RowReader reader = new RowReader(tempReference_row2);
|
||||
row = tempReference_row2.get();
|
||||
Reference<RowReader> tempReference_reader2 =
|
||||
new Reference<RowReader>(reader);
|
||||
Out<Segment> tempOut_segment2
|
||||
= new Out<Segment>();
|
||||
result = SegmentSerializer.read(tempReference_reader2, tempOut_segment2);
|
||||
this.segment = tempOut_segment2.get();
|
||||
reader = tempReference_reader2.get();
|
||||
if (result != Result.SUCCESS) {
|
||||
break;
|
||||
}
|
||||
|
||||
record.set(buffer.Slice(0, span.Length));
|
||||
buffer = buffer.Slice(span.Length);
|
||||
need.set(0);
|
||||
this.state = State.NEED_HEADER;
|
||||
consumed.set(buffer.Length - buffer.Length);
|
||||
type.set(ProductionType.SEGMENT);
|
||||
return Result.SUCCESS;
|
||||
}
|
||||
|
||||
case NEED_HEADER: {
|
||||
if (buffer.Length < HybridRowHeader.BYTES) {
|
||||
need.set(HybridRowHeader.BYTES);
|
||||
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 -
|
||||
// these cannot be converted using the 'Out' helper class unless the method is within the code
|
||||
// being modified:
|
||||
MemoryMarshal.TryRead(buffer.Span, out header);
|
||||
if (header.Version != HybridRowVersion.V1) {
|
||||
result = Result.INVALID_ROW;
|
||||
break;
|
||||
}
|
||||
|
||||
if (SchemaId.opEquals(header.SchemaId,
|
||||
SystemSchema.SEGMENT_SCHEMA_ID)) {
|
||||
// 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)) {
|
||||
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
|
||||
goto case State.NEED_RECORD
|
||||
}
|
||||
|
||||
result = Result.INVALID_ROW;
|
||||
break;
|
||||
}
|
||||
|
||||
case NEED_RECORD: {
|
||||
int minimalRecordRowSize = HybridRowHeader.BYTES + RecordIOFormatter.RECORD_LAYOUT.size();
|
||||
if (buffer.Length < minimalRecordRowSize) {
|
||||
need.set(minimalRecordRowSize);
|
||||
consumed.set(buffer.Length - buffer.Length);
|
||||
return Result.INSUFFICIENT_BUFFER;
|
||||
}
|
||||
|
||||
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||
//ORIGINAL LINE: Span<byte> span = b.Span.Slice(0, minimalRecordRowSize);
|
||||
Span<Byte> span = buffer.Span.Slice(0, minimalRecordRowSize);
|
||||
RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.layoutResolver);
|
||||
Reference<RowBuffer> tempReference_row3 =
|
||||
new Reference<RowBuffer>(row);
|
||||
RowReader reader = new RowReader(tempReference_row3);
|
||||
row = tempReference_row3.get();
|
||||
Reference<RowReader> tempReference_reader3 = new Reference<RowReader>(reader);
|
||||
Out<Record> tempOut_record = new Out<Record>();
|
||||
result = RecordSerializer.read(tempReference_reader3, tempOut_record);
|
||||
this.record = tempOut_record.get();
|
||||
reader = tempReference_reader3.get();
|
||||
if (result != Result.SUCCESS) {
|
||||
break;
|
||||
}
|
||||
|
||||
buffer = buffer.Slice(span.Length);
|
||||
this.state = 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()) {
|
||||
need.set(this.record.length());
|
||||
consumed.set(buffer.Length - buffer.Length);
|
||||
return Result.INSUFFICIENT_BUFFER;
|
||||
}
|
||||
|
||||
record.set(buffer.Slice(0, this.record.length()));
|
||||
|
||||
// Validate that the record has not been corrupted.
|
||||
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||
//ORIGINAL LINE: uint crc32 = Crc32.Update(0, record.Span);
|
||||
int crc32 = Crc32.Update(0, record.get().Span);
|
||||
if (crc32 != this.record.crc32()) {
|
||||
result = Result.INVALID_ROW;
|
||||
break;
|
||||
}
|
||||
|
||||
buffer = buffer.Slice(this.record.length());
|
||||
need.set(0);
|
||||
this.state = State.NEED_HEADER;
|
||||
consumed.set(buffer.Length - buffer.Length);
|
||||
type.set(ProductionType.RECORD);
|
||||
return Result.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
this.state = State.ERROR;
|
||||
need.set(0);
|
||||
consumed.set(buffer.Length - buffer.Length);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* True if a valid segment has been parsed.
|
||||
*/
|
||||
public boolean haveSegment() {
|
||||
return this.state.value() >= State.NEED_HEADER.value();
|
||||
}
|
||||
|
||||
/**
|
||||
* If a valid segment has been parsed then current active segment, otherwise undefined.
|
||||
*/
|
||||
public Segment segment() {
|
||||
checkState(this.haveSegment());
|
||||
return this.segment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes the type of Hybrid Rows produced by the parser.
|
||||
*/
|
||||
public enum ProductionType {
|
||||
/**
|
||||
* No hybrid row was produced. The parser needs more data.
|
||||
*/
|
||||
NONE(0),
|
||||
|
||||
/**
|
||||
* A new segment row was produced.
|
||||
*/
|
||||
SEGMENT(1),
|
||||
|
||||
/**
|
||||
* A record in the current segment was produced.
|
||||
*/
|
||||
RECORD(2);
|
||||
|
||||
public static final int BYTES = Integer.BYTES;
|
||||
|
||||
private static Int2ObjectMap<ProductionType> mappings;
|
||||
private int value;
|
||||
|
||||
ProductionType(int value) {
|
||||
this.value = value;
|
||||
mappings().put(value, this);
|
||||
}
|
||||
|
||||
public int value() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public static ProductionType from(int value) {
|
||||
return mappings().get(value);
|
||||
}
|
||||
|
||||
private static Int2ObjectMap<ProductionType> mappings() {
|
||||
if (mappings == null) {
|
||||
synchronized (ProductionType.class) {
|
||||
if (mappings == null) {
|
||||
mappings = new Int2ObjectOpenHashMap<>();
|
||||
}
|
||||
}
|
||||
}
|
||||
return mappings;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The states for the internal state machine.
|
||||
* Note: numerical ordering of these states matters.
|
||||
*/
|
||||
private enum State {
|
||||
STATE(
|
||||
(byte) 0, "Start: no buffers have yet been provided to the parser"),
|
||||
ERROR(
|
||||
(byte) 1, "Unrecoverable parse error encountered"),
|
||||
NEED_SEGMENT_LENGTH(
|
||||
(byte) 2, "Parsing segment header length"),
|
||||
NEED_SEGMENT(
|
||||
(byte) 3, "Parsing segment header"),
|
||||
NEED_HEADER(
|
||||
(byte) 4, "Parsing HybridRow header"),
|
||||
NEED_RECORD(
|
||||
(byte) 5, "Parsing record header"),
|
||||
NEED_ROW(
|
||||
(byte) 6, "Parsing row body");
|
||||
|
||||
public static final int BYTES = Byte.SIZE;
|
||||
|
||||
private static Byte2ObjectMap<State> mappings;
|
||||
private final String description;
|
||||
private final byte value;
|
||||
|
||||
State(byte value, String description) {
|
||||
this.description = description;
|
||||
this.value = value;
|
||||
mappings().put(value, this);
|
||||
}
|
||||
|
||||
public String description() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public byte value() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public static State from(byte value) {
|
||||
return mappings().get(value);
|
||||
}
|
||||
|
||||
private static Byte2ObjectMap<State> mappings() {
|
||||
if (mappings == null) {
|
||||
synchronized (State.class) {
|
||||
if (mappings == null) {
|
||||
mappings = new Byte2ObjectOpenHashMap<>();
|
||||
}
|
||||
}
|
||||
}
|
||||
return mappings;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,368 +1,368 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
package com.azure.data.cosmos.serialization.hybridrow.recordio;
|
||||
|
||||
import com.azure.data.cosmos.core.Out;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.MemorySpanResizer;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.Result;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public final class RecordIOStream {
|
||||
/**
|
||||
* A function that produces RecordIO record bodies.
|
||||
* <p>
|
||||
* Record bodies are returned as memory blocks. It is expected that each block is a
|
||||
* HybridRow, but any binary data is allowed.
|
||||
*
|
||||
* @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.
|
||||
* And, the byte sequence of the record body's row buffer.
|
||||
*/
|
||||
public delegate ValueTask
|
||||
|
||||
ProduceFuncAsync(long index);<(Result,ReadOnlyMemory<Byte>)>
|
||||
|
||||
/**
|
||||
* Reads an entire RecordIO stream.
|
||||
*
|
||||
* @param stm The stream to read from.
|
||||
* @param visitRecord A (required) delegate that is called once for each record.
|
||||
* <p>
|
||||
* <paramref name="visitRecord" /> is passed a {@link Memory{T}} of the byte sequence
|
||||
* of the
|
||||
* record body's row buffer.
|
||||
* </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.
|
||||
* <p>
|
||||
* If <paramref name="visitSegment" /> is not provided then segment headers are parsed but
|
||||
* skipped
|
||||
* over.
|
||||
* </p>
|
||||
* <p>
|
||||
* <paramref name="visitSegment" /> is passed a {@link Memory{T}} of the byte sequence of
|
||||
* the segment header's row buffer.
|
||||
* </p>
|
||||
* <p>If <paramref name="visitSegment" /> returns an error then the sequence is aborted.</p>
|
||||
* @param resizer Optional memory resizer.
|
||||
* @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,
|
||||
Func<Memory<Byte>, Result> visitSegment) {
|
||||
return ReadRecordIOAsync(stm, visitRecord, visitSegment, null);
|
||||
}
|
||||
|
||||
public static Task<Result> ReadRecordIOAsync(Stream stm, Func<Memory<Byte>, Result> visitRecord) {
|
||||
return ReadRecordIOAsync(stm, visitRecord, null, null);
|
||||
}
|
||||
|
||||
// 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>
|
||||
// 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 WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||
public static Task<Result> ReadRecordIOAsync(InputStream stm,
|
||||
tangible.Func1Param<Memory<Byte>, Result> visitRecord,
|
||||
tangible.Func1Param<Memory<Byte>, Result> visitSegment,
|
||||
MemorySpanResizer<Byte> resizer) {
|
||||
checkArgument(stm != null);
|
||||
checkArgument(visitRecord != null);
|
||||
|
||||
// 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:
|
||||
//ORIGINAL LINE: resizer = resizer != null ? resizer : new MemorySpanResizer<byte>();
|
||||
resizer = resizer != null ? resizer : new MemorySpanResizer<Byte>();
|
||||
|
||||
RecordIOParser parser = null;
|
||||
int need = 0;
|
||||
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||
//ORIGINAL LINE: Memory<byte> active = resizer.Memory;
|
||||
Memory<Byte> active = resizer.getMemory();
|
||||
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||
//ORIGINAL LINE: Memory<byte> avail = default;
|
||||
Memory<Byte> avail = null;
|
||||
while (true) {
|
||||
checkState(avail.Length < active.Length);
|
||||
checkState(active.Length > 0);
|
||||
checkState(active.Length >= need);
|
||||
|
||||
// TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java:
|
||||
int read = await stm.ReadAsync(active.Slice(avail.Length));
|
||||
if (read == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
avail = active.Slice(0, avail.Length + read);
|
||||
|
||||
// If there isn't enough data to move the parser forward then just read again.
|
||||
if (avail.Length < need) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Process the available data until no more forward progress is possible.
|
||||
while (avail.Length > 0) {
|
||||
// Loop around processing available data until we don't have anymore
|
||||
RecordIOParser.ProductionType prodType;
|
||||
Out<RecordIOParser.ProductionType> tempOut_prodType = new Out<RecordIOParser.ProductionType>();
|
||||
Memory<Byte> record;
|
||||
Out<Memory<Byte>> tempOut_record = new Out<Memory<Byte>>();
|
||||
Out<Integer> tempOut_need = new Out<Integer>();
|
||||
int consumed;
|
||||
Out<Integer> tempOut_consumed = new Out<Integer>();
|
||||
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||
//ORIGINAL LINE: Result r = parser.Process(avail, out RecordIOParser.ProductionType prodType, out
|
||||
// Memory<byte> record, out need, out int consumed);
|
||||
Result r = parser.process(avail, tempOut_prodType, tempOut_record, tempOut_need, tempOut_consumed);
|
||||
consumed = tempOut_consumed.get();
|
||||
need = tempOut_need.get();
|
||||
record = tempOut_record.get();
|
||||
prodType = tempOut_prodType.get();
|
||||
|
||||
if ((r != Result.SUCCESS) && (r != Result.INSUFFICIENT_BUFFER)) {
|
||||
return r;
|
||||
}
|
||||
|
||||
active = active.Slice(consumed);
|
||||
avail = avail.Slice(consumed);
|
||||
if (avail.IsEmpty) {
|
||||
active = resizer.getMemory();
|
||||
}
|
||||
|
||||
// If there wasn't enough data to move the parser forward then get more data.
|
||||
if (r == Result.INSUFFICIENT_BUFFER) {
|
||||
if (need > active.Length) {
|
||||
resizer.Resize(need, avail.Span);
|
||||
active = resizer.getMemory();
|
||||
avail = resizer.getMemory().Slice(0, avail.Length);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// Validate the Segment
|
||||
if (prodType == RecordIOParser.ProductionType.SEGMENT) {
|
||||
checkState(!record.IsEmpty);
|
||||
r = visitSegment == null ? null : visitSegment.invoke(record) != null ?
|
||||
visitSegment.invoke(record) : Result.SUCCESS;
|
||||
if (r != Result.SUCCESS) {
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
// Consume the record.
|
||||
if (prodType == RecordIOParser.ProductionType.RECORD) {
|
||||
checkState(!record.IsEmpty);
|
||||
|
||||
r = visitRecord.invoke(record);
|
||||
if (r != Result.SUCCESS) {
|
||||
return r;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure we processed all of the available data.
|
||||
checkState(avail.Length == 0);
|
||||
return Result.SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a RecordIO segment into a stream.
|
||||
*
|
||||
* @param stm The stream to write to.
|
||||
* @param segment The segment header to write.
|
||||
* @param produce A function to produces the record bodies for the segment.
|
||||
* <p>
|
||||
* 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.
|
||||
* </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.
|
||||
* <p>
|
||||
* <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.
|
||||
* </p>
|
||||
* @return Success if the stream is written without error, the error code otherwise.
|
||||
*/
|
||||
|
||||
public static Task<Result> WriteRecordIOAsync(Stream stm, Segment segment, ProduceFunc produce) {
|
||||
return WriteRecordIOAsync(stm, segment, produce, null);
|
||||
}
|
||||
|
||||
//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
|
||||
// produce, MemorySpanResizer<byte> resizer = default)
|
||||
// TODO: C# TO JAVA CONVERTER: C# to Java Converter cannot determine whether this System.IO.Stream is input or
|
||||
// output:
|
||||
//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,
|
||||
MemorySpanResizer<Byte> resizer) {
|
||||
return RecordIOStream.WriteRecordIOAsync(stm,
|
||||
segment.clone(), index ->
|
||||
{
|
||||
ReadOnlyMemory<Byte> buffer;
|
||||
Out<ReadOnlyMemory<Byte>> tempOut_buffer = new Out<ReadOnlyMemory<Byte>>();
|
||||
buffer = tempOut_buffer.get();
|
||||
return new ValueTask<(Result, ReadOnlyMemory < Byte >) > ((r,buffer))
|
||||
}, resizer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a RecordIO segment into a stream.
|
||||
*
|
||||
* @param stm The stream to write to.
|
||||
* @param segment The segment header to write.
|
||||
* @param produce A function to produces the record bodies for the segment.
|
||||
* <p>
|
||||
* 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.
|
||||
* </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.
|
||||
* <p>
|
||||
* <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.
|
||||
* </p>
|
||||
* @return Success if the stream is written without error, the error code otherwise.
|
||||
*/
|
||||
|
||||
public static Task<Result> WriteRecordIOAsync(Stream stm, Segment segment, ProduceFuncAsync produce) {
|
||||
return WriteRecordIOAsync(stm, segment, produce, null);
|
||||
}
|
||||
|
||||
// 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,
|
||||
// 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 WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||
public static Task<Result> WriteRecordIOAsync(OutputStream stm, Segment segment, ProduceFuncAsync produce,
|
||||
MemorySpanResizer<Byte> resizer) {
|
||||
// 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:
|
||||
//ORIGINAL LINE: resizer = resizer != null ? resizer : new MemorySpanResizer<byte>();
|
||||
resizer = resizer != null ? resizer : new MemorySpanResizer<Byte>();
|
||||
|
||||
// Write a RecordIO stream.
|
||||
Memory<Byte> metadata;
|
||||
Out<Memory<Byte>> tempOut_metadata = new Out<Memory<Byte>>();
|
||||
//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);
|
||||
Result r = RecordIOStream.FormatSegment(segment.clone(), resizer, tempOut_metadata);
|
||||
metadata = tempOut_metadata.get();
|
||||
if (r != Result.SUCCESS) {
|
||||
return r;
|
||||
}
|
||||
|
||||
// TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java:
|
||||
await stm.WriteAsync(metadata);
|
||||
|
||||
long index = 0;
|
||||
while (true) {
|
||||
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||
//ORIGINAL LINE: ReadOnlyMemory<byte> body;
|
||||
ReadOnlyMemory<Byte> body;
|
||||
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to the C# deconstruction assignments:
|
||||
(r, body) =await produce (index++);
|
||||
if (r != Result.SUCCESS) {
|
||||
return r;
|
||||
}
|
||||
|
||||
if (body.IsEmpty) {
|
||||
break;
|
||||
}
|
||||
|
||||
Out<Memory<Byte>> tempOut_metadata2 = new Out<Memory<Byte>>();
|
||||
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||
//ORIGINAL LINE: r = RecordIOStream.FormatRow(body, resizer, out metadata);
|
||||
r = RecordIOStream.FormatRow(body, resizer, tempOut_metadata2);
|
||||
metadata = tempOut_metadata2.get();
|
||||
if (r != Result.SUCCESS) {
|
||||
return r;
|
||||
}
|
||||
|
||||
// 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
|
||||
// was incorrectly used for both. Check the resizer parameter passed to
|
||||
// WriteRecordIOAsync for metadata.
|
||||
checkState(!metadata.Span.Overlaps(body.Span));
|
||||
|
||||
// TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java:
|
||||
await stm.WriteAsync(metadata);
|
||||
// TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java:
|
||||
await stm.WriteAsync(body);
|
||||
}
|
||||
|
||||
return Result.SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute and format a record header for the given record body.
|
||||
*
|
||||
* @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 block The byte sequence of the written row buffer.
|
||||
* @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:
|
||||
//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) {
|
||||
RowBuffer row;
|
||||
Out<RowBuffer> tempOut_row = new Out<RowBuffer>();
|
||||
Result r = RecordIOFormatter.FormatRecord(body, tempOut_row, resizer);
|
||||
row = tempOut_row.get();
|
||||
if (r != Result.SUCCESS) {
|
||||
block.setAndGet(null);
|
||||
return r;
|
||||
}
|
||||
|
||||
block.setAndGet(resizer.getMemory().Slice(0, row.Length));
|
||||
return Result.SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a segment.
|
||||
*
|
||||
* @param segment The segment to format.
|
||||
* @param resizer The resizer to use in allocating a buffer for the segment.
|
||||
* @param block The byte sequence of the written row buffer.
|
||||
* @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:
|
||||
//ORIGINAL LINE: private static Result FormatSegment(Segment segment, MemorySpanResizer<byte> resizer, out
|
||||
// Memory<byte> block)
|
||||
private static Result FormatSegment(Segment segment, MemorySpanResizer<Byte> resizer,
|
||||
Out<Memory<Byte>> block) {
|
||||
RowBuffer row;
|
||||
Out<RowBuffer> tempOut_row =
|
||||
new Out<RowBuffer>();
|
||||
Result r = RecordIOFormatter.FormatSegment(segment.clone(), tempOut_row, resizer);
|
||||
row = tempOut_row.get();
|
||||
if (r != Result.SUCCESS) {
|
||||
block.setAndGet(null);
|
||||
return r;
|
||||
}
|
||||
|
||||
block.setAndGet(resizer.getMemory().Slice(0, row.Length));
|
||||
return Result.SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* A function that produces RecordIO record bodies.
|
||||
* <p>
|
||||
* Record bodies are returned as memory blocks. It is expected that each block is a
|
||||
* HybridRow, but any binary data is allowed.
|
||||
*
|
||||
* @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.
|
||||
* @return Success if the body was produced without error, the error code otherwise.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface ProduceFunc {
|
||||
Result invoke(long index, Out<ReadOnlyMemory<Byte>> buffer);
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
package com.azure.data.cosmos.serialization.hybridrow.recordio;
|
||||
|
||||
import com.azure.data.cosmos.core.Out;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.MemorySpanResizer;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.Result;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public final class RecordIOStream {
|
||||
/**
|
||||
* A function that produces RecordIO record bodies.
|
||||
* <p>
|
||||
* Record bodies are returned as memory blocks. It is expected that each block is a
|
||||
* HybridRow, but any binary data is allowed.
|
||||
*
|
||||
* @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.
|
||||
* And, the byte sequence of the record body's row buffer.
|
||||
*/
|
||||
public delegate ValueTask
|
||||
|
||||
ProduceFuncAsync(long index);<(Result,ReadOnlyMemory<Byte>)>
|
||||
|
||||
/**
|
||||
* Reads an entire RecordIO stream.
|
||||
*
|
||||
* @param stm The stream to read from.
|
||||
* @param visitRecord A (required) delegate that is called once for each record.
|
||||
* <p>
|
||||
* <paramref name="visitRecord" /> is passed a {@link Memory{T}} of the byte sequence
|
||||
* of the
|
||||
* record body's row buffer.
|
||||
* </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.
|
||||
* <p>
|
||||
* If <paramref name="visitSegment" /> is not provided then segment headers are parsed but
|
||||
* skipped
|
||||
* over.
|
||||
* </p>
|
||||
* <p>
|
||||
* <paramref name="visitSegment" /> is passed a {@link Memory{T}} of the byte sequence of
|
||||
* the segment header's row buffer.
|
||||
* </p>
|
||||
* <p>If <paramref name="visitSegment" /> returns an error then the sequence is aborted.</p>
|
||||
* @param resizer Optional memory resizer.
|
||||
* @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,
|
||||
Func<Memory<Byte>, Result> visitSegment) {
|
||||
return ReadRecordIOAsync(stm, visitRecord, visitSegment, null);
|
||||
}
|
||||
|
||||
public static Task<Result> ReadRecordIOAsync(Stream stm, Func<Memory<Byte>, Result> visitRecord) {
|
||||
return ReadRecordIOAsync(stm, visitRecord, null, null);
|
||||
}
|
||||
|
||||
// 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>
|
||||
// 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 WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||
public static Task<Result> ReadRecordIOAsync(InputStream stm,
|
||||
tangible.Func1Param<Memory<Byte>, Result> visitRecord,
|
||||
tangible.Func1Param<Memory<Byte>, Result> visitSegment,
|
||||
MemorySpanResizer<Byte> resizer) {
|
||||
checkArgument(stm != null);
|
||||
checkArgument(visitRecord != null);
|
||||
|
||||
// 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:
|
||||
//ORIGINAL LINE: resizer = resizer != null ? resizer : new MemorySpanResizer<byte>();
|
||||
resizer = resizer != null ? resizer : new MemorySpanResizer<Byte>();
|
||||
|
||||
RecordIOParser parser = null;
|
||||
int need = 0;
|
||||
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||
//ORIGINAL LINE: Memory<byte> active = resizer.Memory;
|
||||
Memory<Byte> active = resizer.getMemory();
|
||||
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||
//ORIGINAL LINE: Memory<byte> avail = default;
|
||||
Memory<Byte> avail = null;
|
||||
while (true) {
|
||||
checkState(avail.Length < active.Length);
|
||||
checkState(active.Length > 0);
|
||||
checkState(active.Length >= need);
|
||||
|
||||
// TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java:
|
||||
int read = await stm.ReadAsync(active.Slice(avail.Length));
|
||||
if (read == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
avail = active.Slice(0, avail.Length + read);
|
||||
|
||||
// If there isn't enough data to move the parser forward then just read again.
|
||||
if (avail.Length < need) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Process the available data until no more forward progress is possible.
|
||||
while (avail.Length > 0) {
|
||||
// Loop around processing available data until we don't have anymore
|
||||
RecordIOParser.ProductionType prodType;
|
||||
Out<RecordIOParser.ProductionType> tempOut_prodType = new Out<RecordIOParser.ProductionType>();
|
||||
Memory<Byte> record;
|
||||
Out<Memory<Byte>> tempOut_record = new Out<Memory<Byte>>();
|
||||
Out<Integer> tempOut_need = new Out<Integer>();
|
||||
int consumed;
|
||||
Out<Integer> tempOut_consumed = new Out<Integer>();
|
||||
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||
//ORIGINAL LINE: Result r = parser.Process(avail, out RecordIOParser.ProductionType prodType, out
|
||||
// Memory<byte> record, out need, out int consumed);
|
||||
Result r = parser.process(avail, tempOut_prodType, tempOut_record, tempOut_need, tempOut_consumed);
|
||||
consumed = tempOut_consumed.get();
|
||||
need = tempOut_need.get();
|
||||
record = tempOut_record.get();
|
||||
prodType = tempOut_prodType.get();
|
||||
|
||||
if ((r != Result.SUCCESS) && (r != Result.INSUFFICIENT_BUFFER)) {
|
||||
return r;
|
||||
}
|
||||
|
||||
active = active.Slice(consumed);
|
||||
avail = avail.Slice(consumed);
|
||||
if (avail.IsEmpty) {
|
||||
active = resizer.getMemory();
|
||||
}
|
||||
|
||||
// If there wasn't enough data to move the parser forward then get more data.
|
||||
if (r == Result.INSUFFICIENT_BUFFER) {
|
||||
if (need > active.Length) {
|
||||
resizer.Resize(need, avail.Span);
|
||||
active = resizer.getMemory();
|
||||
avail = resizer.getMemory().Slice(0, avail.Length);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// Validate the Segment
|
||||
if (prodType == RecordIOParser.ProductionType.SEGMENT) {
|
||||
checkState(!record.IsEmpty);
|
||||
r = visitSegment == null ? null : visitSegment.invoke(record) != null ?
|
||||
visitSegment.invoke(record) : Result.SUCCESS;
|
||||
if (r != Result.SUCCESS) {
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
// Consume the record.
|
||||
if (prodType == RecordIOParser.ProductionType.RECORD) {
|
||||
checkState(!record.IsEmpty);
|
||||
|
||||
r = visitRecord.invoke(record);
|
||||
if (r != Result.SUCCESS) {
|
||||
return r;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure we processed all of the available data.
|
||||
checkState(avail.Length == 0);
|
||||
return Result.SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a RecordIO segment into a stream.
|
||||
*
|
||||
* @param stm The stream to write to.
|
||||
* @param segment The segment header to write.
|
||||
* @param produce A function to produces the record bodies for the segment.
|
||||
* <p>
|
||||
* 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.
|
||||
* </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.
|
||||
* <p>
|
||||
* <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.
|
||||
* </p>
|
||||
* @return Success if the stream is written without error, the error code otherwise.
|
||||
*/
|
||||
|
||||
public static Task<Result> WriteRecordIOAsync(Stream stm, Segment segment, ProduceFunc produce) {
|
||||
return WriteRecordIOAsync(stm, segment, produce, null);
|
||||
}
|
||||
|
||||
//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
|
||||
// produce, MemorySpanResizer<byte> resizer = default)
|
||||
// TODO: C# TO JAVA CONVERTER: C# to Java Converter cannot determine whether this System.IO.Stream is input or
|
||||
// output:
|
||||
//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,
|
||||
MemorySpanResizer<Byte> resizer) {
|
||||
return RecordIOStream.WriteRecordIOAsync(stm,
|
||||
segment.clone(), index ->
|
||||
{
|
||||
ReadOnlyMemory<Byte> buffer;
|
||||
Out<ReadOnlyMemory<Byte>> tempOut_buffer = new Out<ReadOnlyMemory<Byte>>();
|
||||
buffer = tempOut_buffer.get();
|
||||
return new ValueTask<(Result, ReadOnlyMemory < Byte >) > ((r,buffer))
|
||||
}, resizer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a RecordIO segment into a stream.
|
||||
*
|
||||
* @param stm The stream to write to.
|
||||
* @param segment The segment header to write.
|
||||
* @param produce A function to produces the record bodies for the segment.
|
||||
* <p>
|
||||
* 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.
|
||||
* </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.
|
||||
* <p>
|
||||
* <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.
|
||||
* </p>
|
||||
* @return Success if the stream is written without error, the error code otherwise.
|
||||
*/
|
||||
|
||||
public static Task<Result> WriteRecordIOAsync(Stream stm, Segment segment, ProduceFuncAsync produce) {
|
||||
return WriteRecordIOAsync(stm, segment, produce, null);
|
||||
}
|
||||
|
||||
// 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,
|
||||
// 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 WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||
public static Task<Result> WriteRecordIOAsync(OutputStream stm, Segment segment, ProduceFuncAsync produce,
|
||||
MemorySpanResizer<Byte> resizer) {
|
||||
// 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:
|
||||
//ORIGINAL LINE: resizer = resizer != null ? resizer : new MemorySpanResizer<byte>();
|
||||
resizer = resizer != null ? resizer : new MemorySpanResizer<Byte>();
|
||||
|
||||
// Write a RecordIO stream.
|
||||
Memory<Byte> metadata;
|
||||
Out<Memory<Byte>> tempOut_metadata = new Out<Memory<Byte>>();
|
||||
//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);
|
||||
Result r = RecordIOStream.FormatSegment(segment.clone(), resizer, tempOut_metadata);
|
||||
metadata = tempOut_metadata.get();
|
||||
if (r != Result.SUCCESS) {
|
||||
return r;
|
||||
}
|
||||
|
||||
// TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java:
|
||||
await stm.WriteAsync(metadata);
|
||||
|
||||
long index = 0;
|
||||
while (true) {
|
||||
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||
//ORIGINAL LINE: ReadOnlyMemory<byte> body;
|
||||
ReadOnlyMemory<Byte> body;
|
||||
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to the C# deconstruction assignments:
|
||||
(r, body) =await produce (index++);
|
||||
if (r != Result.SUCCESS) {
|
||||
return r;
|
||||
}
|
||||
|
||||
if (body.IsEmpty) {
|
||||
break;
|
||||
}
|
||||
|
||||
Out<Memory<Byte>> tempOut_metadata2 = new Out<Memory<Byte>>();
|
||||
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||
//ORIGINAL LINE: r = RecordIOStream.FormatRow(body, resizer, out metadata);
|
||||
r = RecordIOStream.FormatRow(body, resizer, tempOut_metadata2);
|
||||
metadata = tempOut_metadata2.get();
|
||||
if (r != Result.SUCCESS) {
|
||||
return r;
|
||||
}
|
||||
|
||||
// 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
|
||||
// was incorrectly used for both. Check the resizer parameter passed to
|
||||
// WriteRecordIOAsync for metadata.
|
||||
checkState(!metadata.Span.Overlaps(body.Span));
|
||||
|
||||
// TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java:
|
||||
await stm.WriteAsync(metadata);
|
||||
// TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java:
|
||||
await stm.WriteAsync(body);
|
||||
}
|
||||
|
||||
return Result.SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute and format a record header for the given record body.
|
||||
*
|
||||
* @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 block The byte sequence of the written row buffer.
|
||||
* @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:
|
||||
//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) {
|
||||
RowBuffer row;
|
||||
Out<RowBuffer> tempOut_row = new Out<RowBuffer>();
|
||||
Result r = RecordIOFormatter.FormatRecord(body, tempOut_row, resizer);
|
||||
row = tempOut_row.get();
|
||||
if (r != Result.SUCCESS) {
|
||||
block.setAndGet(null);
|
||||
return r;
|
||||
}
|
||||
|
||||
block.setAndGet(resizer.getMemory().Slice(0, row.Length));
|
||||
return Result.SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a segment.
|
||||
*
|
||||
* @param segment The segment to format.
|
||||
* @param resizer The resizer to use in allocating a buffer for the segment.
|
||||
* @param block The byte sequence of the written row buffer.
|
||||
* @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:
|
||||
//ORIGINAL LINE: private static Result FormatSegment(Segment segment, MemorySpanResizer<byte> resizer, out
|
||||
// Memory<byte> block)
|
||||
private static Result FormatSegment(Segment segment, MemorySpanResizer<Byte> resizer,
|
||||
Out<Memory<Byte>> block) {
|
||||
RowBuffer row;
|
||||
Out<RowBuffer> tempOut_row =
|
||||
new Out<RowBuffer>();
|
||||
Result r = RecordIOFormatter.FormatSegment(segment.clone(), tempOut_row, resizer);
|
||||
row = tempOut_row.get();
|
||||
if (r != Result.SUCCESS) {
|
||||
block.setAndGet(null);
|
||||
return r;
|
||||
}
|
||||
|
||||
block.setAndGet(resizer.getMemory().Slice(0, row.Length));
|
||||
return Result.SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* A function that produces RecordIO record bodies.
|
||||
* <p>
|
||||
* Record bodies are returned as memory blocks. It is expected that each block is a
|
||||
* HybridRow, but any binary data is allowed.
|
||||
*
|
||||
* @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.
|
||||
* @return Success if the body was produced without error, the error code otherwise.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface ProduceFunc {
|
||||
Result invoke(long index, Out<ReadOnlyMemory<Byte>> buffer);
|
||||
}
|
||||
}
|
||||
@@ -1,68 +1,68 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
package com.azure.data.cosmos.serialization.hybridrow.recordio;
|
||||
|
||||
import com.azure.data.cosmos.core.Out;
|
||||
import com.azure.data.cosmos.core.UtfAnyString;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.Result;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.io.RowReader;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.io.RowWriter;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
public final class RecordSerializer {
|
||||
|
||||
@Nonnull
|
||||
public static Result read(RowReader reader, Out<Record> record) {
|
||||
|
||||
Out<Integer> value = new Out<>();
|
||||
record.set(Record.empty());
|
||||
|
||||
while (reader.read()) {
|
||||
|
||||
String path = reader.path().toUtf16();
|
||||
checkState(path != null);
|
||||
Result result;
|
||||
|
||||
// TODO: use Path tokens here
|
||||
|
||||
switch (path) {
|
||||
|
||||
case "length":
|
||||
|
||||
result = reader.readInt32(value);
|
||||
record.get().length(value.get());
|
||||
|
||||
if (result != Result.SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
break;
|
||||
|
||||
case "crc32":
|
||||
|
||||
result = reader.readInt32(value);
|
||||
record.get().crc32(value.get());
|
||||
|
||||
if (result != Result.SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return Result.SUCCESS;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static Result write(RowWriter writer, TypeArgument typeArg, Record record) {
|
||||
Result result = writer.writeInt32(new UtfAnyString("length"), record.length());
|
||||
if (result != Result.SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
return writer.writeUInt32(new UtfAnyString("crc32"), record.crc32());
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
package com.azure.data.cosmos.serialization.hybridrow.recordio;
|
||||
|
||||
import com.azure.data.cosmos.core.Out;
|
||||
import com.azure.data.cosmos.core.UtfAnyString;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.Result;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.io.RowReader;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.io.RowWriter;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
public final class RecordSerializer {
|
||||
|
||||
@Nonnull
|
||||
public static Result read(RowReader reader, Out<Record> record) {
|
||||
|
||||
Out<Integer> value = new Out<>();
|
||||
record.set(Record.empty());
|
||||
|
||||
while (reader.read()) {
|
||||
|
||||
String path = reader.path().toUtf16();
|
||||
checkState(path != null);
|
||||
Result result;
|
||||
|
||||
// TODO: use Path tokens here
|
||||
|
||||
switch (path) {
|
||||
|
||||
case "length":
|
||||
|
||||
result = reader.readInt32(value);
|
||||
record.get().length(value.get());
|
||||
|
||||
if (result != Result.SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
break;
|
||||
|
||||
case "crc32":
|
||||
|
||||
result = reader.readInt32(value);
|
||||
record.get().crc32(value.get());
|
||||
|
||||
if (result != Result.SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return Result.SUCCESS;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static Result write(RowWriter writer, TypeArgument typeArg, Record record) {
|
||||
Result result = writer.writeInt32(new UtfAnyString("length"), record.length());
|
||||
if (result != Result.SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
return writer.writeUInt32(new UtfAnyString("crc32"), record.crc32());
|
||||
}
|
||||
}
|
||||
@@ -1,120 +1,123 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
package com.azure.data.cosmos.serialization.hybridrow.recordio;
|
||||
|
||||
import com.azure.data.cosmos.core.Out;
|
||||
import com.azure.data.cosmos.core.Utf8String;
|
||||
import com.azure.data.cosmos.core.UtfAnyString;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.Result;
|
||||
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.RowWriter;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutResolver;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
public final class SegmentSerializer {
|
||||
|
||||
private static final UtfAnyString COMMENT = new UtfAnyString("comment");
|
||||
private static final UtfAnyString LENGTH = new UtfAnyString("length");
|
||||
private static final UtfAnyString SDL = new UtfAnyString("sdl");
|
||||
|
||||
public static Result read(ByteBuf buffer, LayoutResolver resolver, Out<Segment> segment) {
|
||||
RowReader reader = new RowReader(new RowBuffer(buffer, HybridRowVersion.V1, resolver));
|
||||
return SegmentSerializer.read(reader, segment);
|
||||
}
|
||||
|
||||
public static Result read(RowReader reader, Out<Segment> segment) {
|
||||
|
||||
segment.set(new Segment(null, null));
|
||||
|
||||
final Out<Utf8String> comment = new Out<>();
|
||||
final Out<Integer> length = new Out<>();
|
||||
final Out<Utf8String> sdl = new Out<>();
|
||||
|
||||
while (reader.read()) {
|
||||
|
||||
// TODO: Use Path tokens here.
|
||||
|
||||
switch (reader.path().toString()) {
|
||||
|
||||
case "length": {
|
||||
|
||||
Result result = reader.readInt32(length);
|
||||
segment.get().length(length.get());
|
||||
|
||||
if (result != Result.SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (reader.length() < segment.get().length()) {
|
||||
// RowBuffer isn't big enough to contain the rest of the header so just return the length
|
||||
return Result.SUCCESS;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case "comment": {
|
||||
|
||||
Result result = reader.readString(comment);
|
||||
segment.get().comment(comment.get().toUtf16());
|
||||
|
||||
if (result != Result.SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case "sdl": {
|
||||
|
||||
Result result = reader.readString(sdl);
|
||||
segment.get().sdl(sdl.get().toUtf16());
|
||||
|
||||
if (result != Result.SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Result.SUCCESS;
|
||||
}
|
||||
|
||||
public static Result write(RowWriter writer, TypeArgument typeArg, Segment segment) {
|
||||
|
||||
Result 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;
|
||||
}
|
||||
}
|
||||
|
||||
// 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.
|
||||
|
||||
int length = writer.length();
|
||||
result = writer.writeInt32(LENGTH, length);
|
||||
if (result != Result.SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
checkState(length == writer.length());
|
||||
return Result.SUCCESS;
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
package com.azure.data.cosmos.serialization.hybridrow.recordio;
|
||||
|
||||
import com.azure.data.cosmos.core.Out;
|
||||
import com.azure.data.cosmos.core.Utf8String;
|
||||
import com.azure.data.cosmos.core.UtfAnyString;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.Result;
|
||||
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.RowWriter;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.io.Segment;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutResolver;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
public final class SegmentSerializer {
|
||||
|
||||
private static final UtfAnyString COMMENT = new UtfAnyString("comment");
|
||||
private static final UtfAnyString LENGTH = new UtfAnyString("length");
|
||||
private static final UtfAnyString SDL = new UtfAnyString("sdl");
|
||||
|
||||
public static Result read(ByteBuf buffer, LayoutResolver resolver, Out<Segment> segment) {
|
||||
RowReader reader = new RowReader(new RowBuffer(buffer, HybridRowVersion.V1, resolver));
|
||||
return SegmentSerializer.read(reader, segment);
|
||||
}
|
||||
|
||||
public static Result read(RowReader reader, Out<Segment> segment) {
|
||||
|
||||
segment.set(new Segment(null, null));
|
||||
|
||||
final Out<String> comment = new Out<>();
|
||||
final Out<Integer> length = new Out<>();
|
||||
final Out<String> sdl = new Out<>();
|
||||
|
||||
while (reader.read()) {
|
||||
|
||||
// TODO: Use Path tokens here.
|
||||
|
||||
switch (Objects.requireNonNull(reader.path().toUtf16())) {
|
||||
|
||||
case "length": {
|
||||
|
||||
Result result = reader.readInt32(length);
|
||||
segment.get().length(length.get());
|
||||
|
||||
if (result != Result.SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (reader.length() < segment.get().length()) {
|
||||
// RowBuffer isn't big enough to contain the rest of the header so just return the length
|
||||
return Result.SUCCESS;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case "comment": {
|
||||
|
||||
Result result = reader.readString(comment);
|
||||
segment.get().comment(comment.get());
|
||||
|
||||
if (result != Result.SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case "sdl": {
|
||||
|
||||
Result result = reader.readString(sdl);
|
||||
segment.get().sdl(sdl.get());
|
||||
|
||||
if (result != Result.SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Result.SUCCESS;
|
||||
}
|
||||
|
||||
public static Result write(RowWriter writer, TypeArgument typeArg, Segment segment) {
|
||||
|
||||
Result 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;
|
||||
}
|
||||
}
|
||||
|
||||
// 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.
|
||||
|
||||
int length = writer.length();
|
||||
result = writer.writeInt32(LENGTH, length);
|
||||
if (result != Result.SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
checkState(length == writer.length());
|
||||
return Result.SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -6,15 +6,15 @@ package com.azure.data.cosmos.serialization.hybridrow;
|
||||
/**
|
||||
* The literal null value.
|
||||
* <p>
|
||||
* May be stored hybrid row to indicate the literal null value. Typically this value should
|
||||
* not be used and the corresponding column should be absent from the row.
|
||||
* May be stored hybrid row to indicate the literal null value. Typically this value should not be used and the
|
||||
* corresponding column should be absent from the row.
|
||||
*/
|
||||
public final class NullValue {
|
||||
/**
|
||||
* The default null literal.
|
||||
* 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}.
|
||||
|
||||
@@ -625,7 +625,7 @@ public final class RowBuffer {
|
||||
this.readSparsePrimitiveTypeCode(edit, LayoutTypes.NULL);
|
||||
edit.endOffset(edit.valueOffset());
|
||||
|
||||
return NullValue.Default;
|
||||
return NullValue.DEFAULT;
|
||||
}
|
||||
|
||||
public Utf8String readSparsePath(@Nonnull final RowCursor edit) {
|
||||
@@ -843,22 +843,22 @@ public final class RowBuffer {
|
||||
*
|
||||
* @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
|
||||
* undefined.
|
||||
* </paramref>
|
||||
* <paramref name="edit.MetaOffset">
|
||||
*
|
||||
* {@code edit.MetaOffset}
|
||||
* If found, the offset to the metadata of the field, otherwise a
|
||||
* location to insert the field.
|
||||
* </paramref>
|
||||
* <paramref name="edit.cellType">
|
||||
*
|
||||
* {@code edit.cellType}
|
||||
* If found, the layout code of the matching field found, otherwise
|
||||
* undefined.
|
||||
* </paramref>
|
||||
* <paramref name="edit.ValueOffset">
|
||||
*
|
||||
* {@code edit.ValueOffset}
|
||||
* If found, the offset to the value of the field, otherwise
|
||||
* undefined.
|
||||
* </paramref>.
|
||||
*.
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* <paramref name="edit.Path">
|
||||
* {@code edit.Path}
|
||||
* On success, the path of the field at the given offset, otherwise
|
||||
* undefined.
|
||||
* </paramref>
|
||||
* <paramref name="edit.MetaOffset">
|
||||
*
|
||||
* {@code edit.MetaOffset}
|
||||
* On success, the offset to the metadata of the field, otherwise a
|
||||
* location to insert the field.
|
||||
* </paramref>
|
||||
* <paramref name="edit.cellType">
|
||||
*
|
||||
* {@code edit.cellType}
|
||||
* On success, the layout code of the existing field, otherwise
|
||||
* undefined.
|
||||
* </paramref>
|
||||
* <paramref name="edit.TypeArgs">
|
||||
*
|
||||
* {@code edit.TypeArgs}
|
||||
* On success, the type args of the existing field, otherwise
|
||||
* undefined.
|
||||
* </paramref>
|
||||
* <paramref name="edit.ValueOffset">
|
||||
*
|
||||
* {@code edit.ValueOffset}
|
||||
* On success, the offset to the value of the field, otherwise
|
||||
* undefined.
|
||||
* </paramref>.
|
||||
*.
|
||||
*/
|
||||
private void readSparseMetadata(@Nonnull final RowCursor edit) {
|
||||
|
||||
|
||||
@@ -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.RowCursors;
|
||||
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.LayoutBoolean;
|
||||
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.LayoutNull;
|
||||
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.LayoutTypePrimitive;
|
||||
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.LayoutUInt32;
|
||||
@@ -126,7 +126,7 @@ public final class RowReader {
|
||||
* Read the current field as a fixed length {@code MongoDbObjectId} value
|
||||
*
|
||||
* @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) {
|
||||
// TODO: DANOBLE: Resurrect this method
|
||||
@@ -150,22 +150,6 @@ public final class RowReader {
|
||||
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
|
||||
* <p>
|
||||
@@ -264,64 +248,54 @@ public final class RowReader {
|
||||
*/
|
||||
public boolean read() {
|
||||
|
||||
switch (this.state) {
|
||||
for (; ; ) {
|
||||
|
||||
case NONE: {
|
||||
if (this.cursor.scopeType() instanceof LayoutUDT) {
|
||||
this.state = States.SCHEMATIZED;
|
||||
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
|
||||
// goto case States.Schematized;
|
||||
} else {
|
||||
this.state = States.SPARSE;
|
||||
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
|
||||
// goto case States.Sparse;
|
||||
switch (this.state) {
|
||||
|
||||
case NONE: {
|
||||
this.state = this.cursor.scopeType() instanceof LayoutUDT ? States.SCHEMATIZED : States.SPARSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
case SCHEMATIZED: {
|
||||
case SCHEMATIZED: {
|
||||
|
||||
this.columnIndex++;
|
||||
this.columnIndex++;
|
||||
|
||||
if (this.columnIndex >= this.schematizedCount) {
|
||||
this.state = States.SPARSE;
|
||||
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
|
||||
// goto case States.Sparse;
|
||||
if (this.columnIndex >= this.schematizedCount) {
|
||||
|
||||
this.state = 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);
|
||||
LayoutColumn column = this.columns.get(this.columnIndex);
|
||||
|
||||
if (!this.row.readBit(this.cursor.start(), column.nullBit())) {
|
||||
// Skip schematized values if they aren't present
|
||||
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
|
||||
// goto case States.Schematized;
|
||||
if (!RowCursors.moveNext(this.cursor, this.row)) {
|
||||
this.state = States.DONE;
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
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;
|
||||
case DONE: {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
case DONE: {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the current field as a variable length, sequence of bytes
|
||||
*
|
||||
* @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) {
|
||||
|
||||
@@ -336,6 +310,7 @@ public final class RowReader {
|
||||
value.set(null);
|
||||
return Result.TYPE_MISMATCH;
|
||||
}
|
||||
|
||||
value.set(this.row.readSparseBinary(this.cursor));
|
||||
return Result.SUCCESS;
|
||||
|
||||
@@ -349,7 +324,7 @@ public final class RowReader {
|
||||
* Read the current field as a variable length, sequence of bytes
|
||||
*
|
||||
* @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) {
|
||||
|
||||
@@ -369,7 +344,7 @@ public final class RowReader {
|
||||
* Read the current field as a {@link Boolean}
|
||||
*
|
||||
* @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) {
|
||||
|
||||
@@ -397,7 +372,7 @@ public final class RowReader {
|
||||
* Read the current field as a fixed length {@code DateTime} value
|
||||
*
|
||||
* @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) {
|
||||
|
||||
@@ -425,7 +400,7 @@ public final class RowReader {
|
||||
* Read the current field as a fixed length decimal value
|
||||
*
|
||||
* @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) {
|
||||
|
||||
@@ -452,7 +427,7 @@ public final class RowReader {
|
||||
* Read the current field as a fixed length, 128-bit, IEEE-encoded floating point value
|
||||
*
|
||||
* @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) {
|
||||
|
||||
@@ -479,7 +454,7 @@ public final class RowReader {
|
||||
* Read the current field as a fixed length, 32-bit, IEEE-encoded floating point value
|
||||
*
|
||||
* @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) {
|
||||
|
||||
@@ -506,7 +481,7 @@ public final class RowReader {
|
||||
* Read the current field as a fixed length, 64-bit, IEEE-encoded floating point value
|
||||
*
|
||||
* @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) {
|
||||
|
||||
@@ -533,7 +508,7 @@ public final class RowReader {
|
||||
* Read the current field as a fixed length GUID value
|
||||
*
|
||||
* @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) {
|
||||
|
||||
@@ -561,7 +536,7 @@ public final class RowReader {
|
||||
* Read the current field as a fixed length, 16-bit, signed integer
|
||||
*
|
||||
* @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) {
|
||||
|
||||
@@ -588,7 +563,7 @@ public final class RowReader {
|
||||
* Read the current field as a fixed length, 32-bit, signed integer
|
||||
*
|
||||
* @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) {
|
||||
|
||||
@@ -615,7 +590,7 @@ public final class RowReader {
|
||||
* Read the current field as a fixed length, 64-bit, signed integer
|
||||
*
|
||||
* @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) {
|
||||
|
||||
@@ -642,7 +617,7 @@ public final class RowReader {
|
||||
* Read the current field as a fixed length, 8-bit, signed integer
|
||||
*
|
||||
* @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) {
|
||||
|
||||
@@ -669,7 +644,7 @@ public final class RowReader {
|
||||
* Read the current field as a null
|
||||
*
|
||||
* @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) {
|
||||
|
||||
@@ -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>
|
||||
* Child readers can be used to read all sparse scope types including typed and untyped objects, arrays, tuples,
|
||||
* set, and maps.
|
||||
@@ -717,9 +692,7 @@ public final class RowReader {
|
||||
* Read the current field as a nested, structured, sparse scope
|
||||
* <p>
|
||||
* Child readers can be used to read all sparse scope types including typed and untyped objects, arrays, tuples,
|
||||
* set, and maps.
|
||||
* <p>
|
||||
* Nested child readers are independent of their parent.
|
||||
* set, and maps. Nested child readers are independent of their parent.
|
||||
*/
|
||||
public @Nonnull RowReader readScope() {
|
||||
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
|
||||
* @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) {
|
||||
|
||||
@@ -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
|
||||
* @return Success if the read is successful, an error code otherwise
|
||||
* @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 readUInt16(Out<Integer> value) {
|
||||
|
||||
@@ -784,7 +773,7 @@ public final class RowReader {
|
||||
* Read the current field as a fixed length, 32-bit, unsigned integer
|
||||
*
|
||||
* @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) {
|
||||
|
||||
@@ -812,7 +801,7 @@ public final class RowReader {
|
||||
* Read the current field as a fixed length, 64-bit, unsigned integer
|
||||
*
|
||||
* @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) {
|
||||
|
||||
@@ -839,7 +828,7 @@ public final class RowReader {
|
||||
* Read the current field as a fixed length, 8-bit, unsigned integer
|
||||
*
|
||||
* @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) {
|
||||
|
||||
@@ -866,7 +855,7 @@ public final class RowReader {
|
||||
* Read the current field as a fixed length {@link UnixDateTime} value
|
||||
*
|
||||
* @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) {
|
||||
|
||||
@@ -893,7 +882,7 @@ public final class RowReader {
|
||||
* Read the current field as a variable length, 7-bit encoded, signed integer
|
||||
*
|
||||
* @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) {
|
||||
|
||||
@@ -920,7 +909,7 @@ public final class RowReader {
|
||||
* Read the current field as a variable length, 7-bit encoded, unsigned integer
|
||||
*
|
||||
* @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) {
|
||||
|
||||
@@ -1012,14 +1001,14 @@ 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 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) {
|
||||
|
||||
final LayoutColumn column = this.columns.get(this.columnIndex);
|
||||
final LayoutType type = this.columns.get(this.columnIndex).type();
|
||||
|
||||
if (!(type instanceof LayoutType<TValue>)) {
|
||||
if (!(type instanceof LayoutTypePrimitive)) {
|
||||
value.set(null);
|
||||
return Result.TYPE_MISMATCH;
|
||||
}
|
||||
@@ -1028,42 +1017,9 @@ public final class RowReader {
|
||||
|
||||
switch (storage) {
|
||||
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:
|
||||
return type.<LayoutType<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);
|
||||
|
||||
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);
|
||||
@@ -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
|
||||
*
|
||||
* @param <TElement> The sub-element type of the field
|
||||
* @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);
|
||||
LayoutType type = this.columns.get(this.columnIndex).type();
|
||||
|
||||
if (!(type instanceof LayoutSpanReadable<?>)) {
|
||||
if (!(type instanceof LayoutListReadable<?>)) {
|
||||
value.set(null);
|
||||
return Result.TYPE_MISMATCH;
|
||||
}
|
||||
@@ -1093,10 +1082,10 @@ public final class RowReader {
|
||||
switch (storage) {
|
||||
|
||||
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:
|
||||
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:
|
||||
assert false : lenientFormat("expected FIXED or VARIABLE column storage, not %s", storage);
|
||||
|
||||
@@ -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
|
||||
* 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 deserializer A function that reads one item from the collection.
|
||||
|
||||
@@ -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.layouts.Layout;
|
||||
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.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.LayoutTypePrimitive;
|
||||
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.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.schemas.StorageKind;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public final class RowWriter {
|
||||
|
||||
@@ -80,11 +83,10 @@ public final class RowWriter {
|
||||
*
|
||||
* @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.
|
||||
* @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
|
||||
*/
|
||||
public Result WriteBinary(UtfAnyString path, byte[] value) {
|
||||
return this.writePrimitive(path, value, LayoutTypes.BINARY,
|
||||
(ref RowWriter w, byte[] v) -> w.row.writeSparseBinary(ref w.cursor, v, UpdateOptions.UPSERT));
|
||||
return this.WriteBinary(path, Unpooled.wrappedBuffer(value));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,24 +94,11 @@ public final class RowWriter {
|
||||
*
|
||||
* @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.
|
||||
* @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
|
||||
*/
|
||||
public Result WriteBinary(UtfAnyString path, ByteBuf value) {
|
||||
return this.writePrimitive(path, value, LayoutTypes.BINARY,
|
||||
(ref RowWriter w, ByteBuf v) -> w.row.writeSparseBinary(ref w.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));
|
||||
return this.writePrimitive(path, value, LayoutTypes.BINARY, (ByteBuf v) ->
|
||||
this.row.writeSparseBinary(this.cursor, v, UpdateOptions.UPSERT));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,21 +106,21 @@ public final class RowWriter {
|
||||
*
|
||||
* @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.
|
||||
* @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
|
||||
*/
|
||||
public Result WriteBoolean(UtfAnyString path, boolean value) {
|
||||
return this.writePrimitive(path, value, LayoutTypes.BOOLEAN,
|
||||
(ref RowWriter w, boolean v) -> w.row.writeSparseBool(ref w.cursor, v, UpdateOptions.UPSERT));
|
||||
return this.writePrimitive(path, value, LayoutTypes.BOOLEAN, (Boolean v) ->
|
||||
this.row.writeSparseBoolean(this.cursor, value, UpdateOptions.UPSERT));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 context A context value to pass to <paramref name="func" />.
|
||||
* @param func A function to write the entire row.
|
||||
* @return Success if the write is successful, an error code otherwise.
|
||||
* @param <TContext> The type of the context value to pass to {@code func}.
|
||||
* @param row The row to write.
|
||||
* @param context A context value to pass to {@code func}.
|
||||
* @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(
|
||||
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 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) {
|
||||
// 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.DATE_TIME,
|
||||
(ref RowWriter w, LocalDateTime v) -> w.row.writeSparseDateTime(ref w.cursor, v, UpdateOptions.UPSERT));
|
||||
public Result writeDateTime(UtfAnyString path, OffsetDateTime value) {
|
||||
return this.writePrimitive(path, value, LayoutTypes.DATE_TIME, (OffsetDateTime v) ->
|
||||
this.row.writeSparseDateTime(this.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 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) {
|
||||
// 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.DECIMAL,
|
||||
(ref RowWriter w, BigDecimal v) -> w.row.writeSparseDecimal(ref w.cursor, v, UpdateOptions.UPSERT));
|
||||
public Result writeDecimal(UtfAnyString path, BigDecimal value) {
|
||||
return this.writePrimitive(path, value, LayoutTypes.DECIMAL, (BigDecimal v) ->
|
||||
this.row.writeSparseDecimal(this.cursor, v, UpdateOptions.UPSERT));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -188,15 +169,11 @@ public final class RowWriter {
|
||||
*
|
||||
* @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.
|
||||
* @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
|
||||
*/
|
||||
public Result WriteFloat128(UtfAnyString path, Float128 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.FLOAT_128,
|
||||
(ref RowWriter w, Float128 v) -> w.row.writeSparseFloat128(ref w.cursor, v, UpdateOptions.UPSERT));
|
||||
public Result writeFloat128(UtfAnyString path, Float128 value) {
|
||||
return this.writePrimitive(path, value, LayoutTypes.FLOAT_128, (Float128 v) ->
|
||||
this.row.writeSparseFloat128(this.cursor, v, UpdateOptions.UPSERT));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -204,15 +181,11 @@ public final class RowWriter {
|
||||
*
|
||||
* @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.
|
||||
* @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
|
||||
*/
|
||||
public Result WriteFloat32(UtfAnyString path, float 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.FLOAT_32,
|
||||
(ref RowWriter w, float v) -> w.row.writeSparseFloat32(ref w.cursor, v, UpdateOptions.UPSERT));
|
||||
public Result writeFloat32(UtfAnyString path, float value) {
|
||||
return this.writePrimitive(path, value, LayoutTypes.FLOAT_32, (Float v) ->
|
||||
this.row.writeSparseFloat32(this.cursor, v, UpdateOptions.UPSERT));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -220,31 +193,23 @@ public final class RowWriter {
|
||||
*
|
||||
* @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.
|
||||
* @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
|
||||
*/
|
||||
public Result WriteFloat64(UtfAnyString path, double 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.FLOAT_64,
|
||||
(ref RowWriter w, double v) -> w.row.writeSparseFloat64(ref w.cursor, v, UpdateOptions.UPSERT));
|
||||
public Result writeFloat64(UtfAnyString path, double value) {
|
||||
return this.writePrimitive(path, value, LayoutTypes.FLOAT_64, (Double v) ->
|
||||
this.row.writeSparseFloat64(this.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 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) {
|
||||
// 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.GUID,
|
||||
(ref RowWriter w, UUID v) -> w.row.writeSparseGuid(ref w.cursor, v, UpdateOptions.UPSERT));
|
||||
public Result writeGuid(UtfAnyString path, UUID value) {
|
||||
return this.writePrimitive(path, value, LayoutTypes.GUID, (UUID v) ->
|
||||
this.row.writeSparseGuid(this.cursor, v, UpdateOptions.UPSERT));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -252,31 +217,11 @@ public final class RowWriter {
|
||||
*
|
||||
* @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.
|
||||
* @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
|
||||
*/
|
||||
public Result WriteInt16(UtfAnyString path, short 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_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));
|
||||
public Result writeInt16(UtfAnyString path, short value) {
|
||||
return this.writePrimitive(path, value, LayoutTypes.INT_16, (Short v) ->
|
||||
this.row.writeSparseInt16(this.cursor, v, UpdateOptions.UPSERT));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -284,15 +229,11 @@ public final class RowWriter {
|
||||
*
|
||||
* @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.
|
||||
* @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
|
||||
*/
|
||||
public Result WriteInt64(UtfAnyString path, long 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_64,
|
||||
(ref RowWriter w, long v) -> w.row.writeSparseInt64(ref w.cursor, v, UpdateOptions.UPSERT));
|
||||
public Result writeInt64(UtfAnyString path, long value) {
|
||||
return this.writePrimitive(path, value, LayoutTypes.INT_64, (Long v) ->
|
||||
this.row.writeSparseInt64(this.cursor, v, UpdateOptions.UPSERT));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -300,15 +241,22 @@ public final class RowWriter {
|
||||
*
|
||||
* @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.
|
||||
* @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
|
||||
*/
|
||||
public Result WriteInt8(UtfAnyString path, byte 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_8,
|
||||
(ref RowWriter w, byte v) -> w.row.writeSparseInt8(ref w.cursor, v, UpdateOptions.UPSERT));
|
||||
public Result writeInt8(UtfAnyString path, byte value) {
|
||||
return this.writePrimitive(path, value, LayoutTypes.INT_8, (Byte v) ->
|
||||
this.row.writeSparseInt8(this.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
|
||||
@@ -317,27 +265,18 @@ public final class RowWriter {
|
||||
// *
|
||||
// * @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.
|
||||
// * @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
|
||||
// */
|
||||
// public Result WriteMongoDbObjectId(UtfAnyString path, MongoDbObjectId value) {
|
||||
// throw new UnsupportedOperationException();
|
||||
// // return this.writePrimitive(path, value, LayoutTypes.MongoDbObjectId, (ref RowWriter w, MongoDbObjectId v) -> w.row.writeSparseMongoDbObjectId(ref w.cursor, v, UpdateOptions.UPSERT));
|
||||
// }
|
||||
|
||||
/**
|
||||
* Write a field as a {@link t:null}.
|
||||
*
|
||||
* @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) {
|
||||
|
||||
public <TContext> Result WriteScope(UtfAnyString path, TypeArgument typeArg, TContext context,
|
||||
WriterFunc<TContext> func) {
|
||||
LayoutType type = typeArg.type();
|
||||
|
||||
Result result = this.prepareSparseWrite(path, typeArg);
|
||||
if (result != Result.SUCCESS) {
|
||||
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 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) {
|
||||
return this.writePrimitive(path, value, LayoutTypes.UTF_8,
|
||||
(ref RowWriter w, String v) -> w.row.writeSparseString(ref w.cursor, Utf8Span.TranscodeUtf16(v),
|
||||
UpdateOptions.UPSERT));
|
||||
public Result writeInt32(UtfAnyString path, int value) {
|
||||
return this.writePrimitive(path, value, LayoutTypes.INT_32, (RowWriter writer, int v) ->
|
||||
writer.row.writeSparseInt32(writer.cursor, v, UpdateOptions.UPSERT));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -560,15 +498,30 @@ public final class RowWriter {
|
||||
*
|
||||
* @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.
|
||||
* @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) {
|
||||
// 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.UTF_8,
|
||||
(ref RowWriter w, Utf8Span v) -> w.row.writeSparseString(ref w.cursor, v, UpdateOptions.UPSERT));
|
||||
return this.writePrimitive(path, value, LayoutTypes.UTF_8, (RowWriter writer, Utf8String v) ->
|
||||
writer.row.writeSparseString(writer.cursor, v, UpdateOptions.UPSERT));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -576,20 +529,11 @@ public final class RowWriter {
|
||||
*
|
||||
* @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.
|
||||
* @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) {
|
||||
// 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:
|
||||
//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));
|
||||
return this.writePrimitive(path, value, LayoutTypes.UINT_16, (RowWriter writer, short v) ->
|
||||
writer.row.writeSparseUInt16(writer.cursor, v, UpdateOptions.UPSERT));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -597,20 +541,11 @@ public final class RowWriter {
|
||||
*
|
||||
* @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.
|
||||
* @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) {
|
||||
// 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:
|
||||
//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));
|
||||
return this.writePrimitive(path, value, LayoutTypes.UINT_32, (RowWriter writer, int v) ->
|
||||
writer.row.writeSparseUInt32(writer.cursor, v, UpdateOptions.UPSERT));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -618,20 +553,11 @@ public final class RowWriter {
|
||||
*
|
||||
* @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.
|
||||
* @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) {
|
||||
// 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:
|
||||
//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));
|
||||
return this.writePrimitive(path, value, LayoutTypes.UINT_64, (RowWriter writer, long v) ->
|
||||
writer.row.writeSparseUInt64(writer.cursor, v, UpdateOptions.UPSERT));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -639,20 +565,11 @@ public final class RowWriter {
|
||||
*
|
||||
* @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.
|
||||
* @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) {
|
||||
// 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:
|
||||
//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));
|
||||
return this.writePrimitive(path, value, LayoutTypes.UINT_8, (RowWriter writer, byte v) ->
|
||||
writer.row.writeSparseUInt8(writer.cursor, v, UpdateOptions.UPSERT));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -660,16 +577,11 @@ public final class RowWriter {
|
||||
*
|
||||
* @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.
|
||||
* @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
|
||||
*/
|
||||
public Result writeUnixDateTime(UtfAnyString path, UnixDateTime 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.UNIX_DATE_TIME,
|
||||
(ref RowWriter w, UnixDateTime v) -> w.row.writeSparseUnixDateTime(ref w.cursor, v,
|
||||
UpdateOptions.UPSERT));
|
||||
return this.writePrimitive(path, value, LayoutTypes.UNIX_DATE_TIME, (RowWriter writer, UnixDateTime v) ->
|
||||
writer.row.writeSparseUnixDateTime(writer.cursor, v, UpdateOptions.UPSERT));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -677,15 +589,11 @@ public final class RowWriter {
|
||||
*
|
||||
* @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.
|
||||
* @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
|
||||
*/
|
||||
public Result writeVarInt(UtfAnyString path, long 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.VAR_INT,
|
||||
(ref RowWriter w, long v) -> w.row.writeSparseVarInt(ref w.cursor, v, UpdateOptions.UPSERT));
|
||||
return this.writePrimitive(path, value, LayoutTypes.VAR_INT, (RowWriter writer, long v) ->
|
||||
writer.row.writeSparseVarInt(writer.cursor, v, UpdateOptions.UPSERT));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -693,20 +601,11 @@ public final class RowWriter {
|
||||
*
|
||||
* @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.
|
||||
* @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) {
|
||||
// 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:
|
||||
//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));
|
||||
return this.writePrimitive(path, value, LayoutTypes.VAR_UINT, (RowWriter writer, long v) ->
|
||||
writer.row.writeSparseVarUInt(writer.cursor, v, UpdateOptions.UPSERT));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -740,15 +639,57 @@ public final class RowWriter {
|
||||
|
||||
/**
|
||||
* 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 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.
|
||||
* @param <TLayoutType> The type of layout type.
|
||||
* @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<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;
|
||||
if (this.cursor.scopeType() instanceof LayoutUDT) {
|
||||
result = this.writeSchematizedValue(path, value);
|
||||
@@ -778,117 +719,33 @@ public final class RowWriter {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @param <TValue> The type of the primitive value.
|
||||
* @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[]> & 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;
|
||||
|
||||
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="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();
|
||||
sparse.accept(this, value);
|
||||
RowCursors.moveNext(this.cursor, this.row);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -896,11 +753,11 @@ public final class RowWriter {
|
||||
|
||||
/**
|
||||
* 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 value The value to write.
|
||||
* @return Success if the write is successful, an error code otherwise.
|
||||
* @param <TValue> The expected type of the field.
|
||||
* @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.
|
||||
*/
|
||||
private <TValue> Result writeSchematizedValue(UtfAnyString path, TValue value) {
|
||||
LayoutColumn col;
|
||||
@@ -943,7 +800,7 @@ public final class RowWriter {
|
||||
*
|
||||
* @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.
|
||||
* @return {@link Result#SUCCESS} if the write is successful, an error {@link Result} otherwise.
|
||||
*/
|
||||
private Result writeSchematizedValue(UtfAnyString path, Utf8String value) {
|
||||
LayoutColumn col;
|
||||
@@ -987,11 +844,11 @@ public final class RowWriter {
|
||||
|
||||
/**
|
||||
* 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 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) {
|
||||
LayoutColumn col;
|
||||
@@ -1027,11 +884,11 @@ public final class RowWriter {
|
||||
|
||||
/**
|
||||
* 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 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) {
|
||||
LayoutColumn col;
|
||||
@@ -1066,23 +923,22 @@ public final class RowWriter {
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
private interface AccessMethod<TValue> {
|
||||
void invoke(Reference<RowWriter> writer, TValue value);
|
||||
private interface AccessMethod<TValue> extends Consumer<TValue> {
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
private interface AccessReadOnlySpanMethod<T> {
|
||||
void invoke(Reference<RowWriter> writer, ReadOnlySpan value);
|
||||
void invoke(RowWriter writer, ReadOnlySpan value);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
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}.
|
||||
* <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 typeArg The type of the current scope.
|
||||
@@ -1091,6 +947,6 @@ public final class RowWriter {
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface WriterFunc<TContext> {
|
||||
Result invoke(Reference<RowWriter> writer, TypeArgument typeArg, TContext context);
|
||||
Result invoke(RowWriter writer, TypeArgument typeArg, TContext context);
|
||||
}
|
||||
}
|
||||
@@ -1,43 +1,43 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
package com.azure.data.cosmos.serialization.hybridrow.recordio;
|
||||
|
||||
public final class Segment {
|
||||
|
||||
private String comment;
|
||||
private int length;
|
||||
private String sdl;
|
||||
|
||||
public Segment(String comment, String sdl) {
|
||||
this.comment = comment;
|
||||
this.sdl = sdl;
|
||||
this.length = 0;
|
||||
}
|
||||
|
||||
public String comment() {
|
||||
return this.comment;
|
||||
}
|
||||
|
||||
public Segment comment(String value) {
|
||||
this.comment = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int length() {
|
||||
return this.length;
|
||||
}
|
||||
|
||||
public Segment length(int value) {
|
||||
this.length = value;
|
||||
return this;
|
||||
}
|
||||
public String sdl() {
|
||||
return this.sdl;
|
||||
}
|
||||
|
||||
public Segment sdl(String value) {
|
||||
this.sdl = value;
|
||||
return this;
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
package com.azure.data.cosmos.serialization.hybridrow.io;
|
||||
|
||||
public final class Segment {
|
||||
|
||||
private String comment;
|
||||
private int length;
|
||||
private String sdl;
|
||||
|
||||
public Segment(String comment, String sdl) {
|
||||
this.comment = comment;
|
||||
this.sdl = sdl;
|
||||
this.length = 0;
|
||||
}
|
||||
|
||||
public String comment() {
|
||||
return this.comment;
|
||||
}
|
||||
|
||||
public Segment comment(String value) {
|
||||
this.comment = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int length() {
|
||||
return this.length;
|
||||
}
|
||||
|
||||
public Segment length(int value) {
|
||||
this.length = value;
|
||||
return this;
|
||||
}
|
||||
public String sdl() {
|
||||
return this.sdl;
|
||||
}
|
||||
|
||||
public Segment sdl(String value) {
|
||||
this.sdl = value;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -18,8 +18,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public final class LayoutBinary extends LayoutTypePrimitive<byte[]> {
|
||||
// implements
|
||||
// LayoutSpanWritable<Byte>,
|
||||
// LayoutSpanReadable<Byte>,
|
||||
// LayoutListWritable<Byte>,
|
||||
// LayoutListReadable<Byte>,
|
||||
// ILayoutSequenceWritable<Byte> {
|
||||
|
||||
public LayoutBinary() {
|
||||
|
||||
@@ -13,7 +13,7 @@ import javax.annotation.Nonnull;
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
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) {
|
||||
super(value ? LayoutCode.BOOLEAN : LayoutCode.BOOLEAN_FALSE, 0);
|
||||
|
||||
@@ -15,11 +15,11 @@ import java.util.List;
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
@@ -14,13 +14,13 @@ import java.util.List;
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
@@ -13,7 +13,7 @@ import javax.annotation.Nonnull;
|
||||
|
||||
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() {
|
||||
super(LayoutCode.NULL, 0);
|
||||
@@ -36,7 +36,7 @@ public final class LayoutNull extends LayoutType<NullValue> {
|
||||
@Nonnull
|
||||
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<NullValue> value) {
|
||||
checkArgument(scope.scopeType() instanceof LayoutUDT);
|
||||
value.set(NullValue.Default);
|
||||
value.set(NullValue.DEFAULT);
|
||||
if (!buffer.readBit(scope.start(), column.nullBit())) {
|
||||
return Result.NOT_FOUND;
|
||||
}
|
||||
|
||||
@@ -343,7 +343,7 @@ public abstract class LayoutType /*implements ILayoutType*/ {
|
||||
* The physical layout type of the field cast to the specified type.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public final <T extends LayoutType> T typeAs() {
|
||||
public final <T extends ILayoutType> T typeAs() {
|
||||
return (T)this;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import javax.annotation.Nonnull;
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
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.
|
||||
*
|
||||
|
||||
@@ -37,9 +37,15 @@ public final class LayoutUtf8 extends LayoutTypePrimitive<String> implements Lay
|
||||
@Nonnull final LayoutColumn column,
|
||||
@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<>();
|
||||
Result result = this.readFixedSpan(buffer, scope, column, span);
|
||||
value.set(result == Result.SUCCESS ? span.get().toUtf16() : null);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* An optional interface that indicates a {@link LayoutType{T}} can also read using a {@link Utf8String}.
|
||||
* An optional interface that indicates a {@link LayoutType{T}} can also be read as a {@link Utf8String}.
|
||||
*/
|
||||
public interface LayoutUtf8Readable extends ILayoutType {
|
||||
|
||||
|
||||
@@ -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.SystemSchema;
|
||||
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.HashMap;
|
||||
|
||||
@@ -80,7 +80,7 @@ public final class JsonModelRowGenerator {
|
||||
new Reference<RowBuffer>(this.row);
|
||||
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not
|
||||
// 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) ->
|
||||
{
|
||||
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) {
|
||||
switch (value) {
|
||||
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:
|
||||
//ORIGINAL LINE: case bool x:
|
||||
case
|
||||
@@ -123,12 +123,12 @@ public final class JsonModelRowGenerator {
|
||||
//ORIGINAL LINE: case long x:
|
||||
case
|
||||
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:
|
||||
//ORIGINAL LINE: case double x:
|
||||
case
|
||||
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:
|
||||
//ORIGINAL LINE: case string x:
|
||||
case String
|
||||
@@ -156,7 +156,7 @@ public final class JsonModelRowGenerator {
|
||||
// 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.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)
|
||||
{
|
||||
@@ -172,7 +172,7 @@ public final class JsonModelRowGenerator {
|
||||
//ORIGINAL LINE: case List<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:
|
||||
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) {
|
||||
Reference<com.azure.data.cosmos.serialization.hybridrow.io.RowWriter> tempReference_writer2 = new Reference<com.azure.data.cosmos.serialization.hybridrow.io.RowWriter>(writer2);
|
||||
|
||||
@@ -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.RowBuffer;
|
||||
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.File;
|
||||
|
||||
@@ -5,7 +5,6 @@ package com.azure.data.cosmos.serialization.hybridrow.unit;
|
||||
|
||||
import Newtonsoft.Json.*;
|
||||
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.NullValue;
|
||||
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("tuple<varint,int64>", value:Tuple.Create(-6148914691236517206L, -6148914691236517206L))
|
||||
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("set_t<utf8>", value:new String[] { "abc", "efg", "xzy" })
|
||||
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("tuple<varint,int64>", value:Tuple.Create(-6148914691236517206L, -6148914691236517206L))
|
||||
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("set_t<utf8>", value:new String[] { "abc", "efg", "xzy" })
|
||||
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("tuple<varint,int64>", value:Tuple.Create(-6148914691236517206L, -6148914691236517206L))
|
||||
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("set_t<utf8>", value:new String[] { "abc", "efg", "xzy" })
|
||||
d.LayoutCodeSwitch("set_t<array_t<int8>>", value:new byte[][]
|
||||
|
||||
@@ -71,7 +71,7 @@ public class LayoutCompilerUnitTests {
|
||||
RoundTripFixed.Expected tempVar = new RoundTripFixed.Expected();
|
||||
tempVar.TypeName = "null";
|
||||
tempVar.Default = new NullValue();
|
||||
tempVar.Value = NullValue.Default;
|
||||
tempVar.Value = NullValue.DEFAULT;
|
||||
RoundTripFixed.Expected tempVar2 = new RoundTripFixed.Expected();
|
||||
tempVar2.TypeName = "bool";
|
||||
tempVar2.Default = false;
|
||||
@@ -1858,7 +1858,7 @@ private final static class RoundTripSparseArray extends TestActionDispatcher<Rou
|
||||
// Overwrite the whole scope.
|
||||
Reference<RowCursor> tempReference_field3 =
|
||||
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();
|
||||
ResultAssert.IsSuccess(r, tag);
|
||||
Reference<RowCursor> tempReference_field4 =
|
||||
@@ -2049,7 +2049,7 @@ private final static class RoundTripSparseObject extends TestActionDispatcher<Ro
|
||||
// Overwrite the whole scope.
|
||||
Reference<RowCursor> tempReference_field4 =
|
||||
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();
|
||||
ResultAssert.IsSuccess(r, "Json: {0}", expected.Json);
|
||||
Reference<RowCursor> tempReference_field5 =
|
||||
@@ -2187,7 +2187,7 @@ private final static class RoundTripSparseObjectMulti extends TestActionDispatch
|
||||
} else {
|
||||
Reference<RowCursor> tempReference_nestedField2 =
|
||||
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();
|
||||
ResultAssert.IsSuccess(r, tag);
|
||||
}
|
||||
@@ -2260,7 +2260,7 @@ private final static class RoundTripSparseObjectMulti extends TestActionDispatch
|
||||
// Overwrite the nested field.
|
||||
Reference<RowCursor> tempReference_nestedField4 =
|
||||
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();
|
||||
ResultAssert.IsSuccess(r, tag);
|
||||
|
||||
@@ -2381,7 +2381,7 @@ private final static class RoundTripSparseObjectNested extends TestActionDispatc
|
||||
} else {
|
||||
Reference<RowCursor> tempReference_field2 =
|
||||
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();
|
||||
ResultAssert.IsSuccess(r, tag);
|
||||
}
|
||||
@@ -2517,7 +2517,7 @@ private final static class RoundTripSparseOrdering extends TestActionDispatcher<
|
||||
} else {
|
||||
Reference<RowCursor> tempReference_field2 =
|
||||
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();
|
||||
ResultAssert.IsSuccess(r, "Json: {0}", json);
|
||||
Out<TValue> tempOut_value3 = new Out<TValue>();
|
||||
@@ -2835,7 +2835,7 @@ private final static class RoundTripSparseSet extends TestActionDispatcher<Round
|
||||
|
||||
// Overwrite the whole scope.
|
||||
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();
|
||||
ResultAssert.IsSuccess(r, tag);
|
||||
Reference<RowCursor> tempReference_field10 = new Reference<RowCursor>(field);
|
||||
@@ -2982,7 +2982,7 @@ private final static class RoundTripSparseSimple extends TestActionDispatcher<Ro
|
||||
} else {
|
||||
Reference<RowCursor> tempReference_field2 =
|
||||
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();
|
||||
ResultAssert.IsSuccess(r, "Json: {0}", expected.Json);
|
||||
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||
|
||||
@@ -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.io.RowReader;
|
||||
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 java.nio.file.Files;
|
||||
|
||||
@@ -174,7 +174,7 @@ public final class RowOperationDispatcher {
|
||||
switch (type.LayoutCode) {
|
||||
case Null:
|
||||
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();
|
||||
break;
|
||||
case Boolean:
|
||||
|
||||
@@ -136,7 +136,7 @@ public final class RowReaderUnitTests {
|
||||
d.LayoutCodeSwitch("array_t<utf8>", value:new String[] { "abc", "def", "hij" })
|
||||
d.LayoutCodeSwitch("tuple<varint,int64>", value:Tuple.Create(-6148914691236517206L, -6148914691236517206L))
|
||||
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("nullable<int32,int64>", value:Tuple.Create(null, (Long)123L))
|
||||
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||
|
||||
@@ -57,7 +57,7 @@ public final class RowWriterUnitTests {
|
||||
new Reference<RowBuffer>(row);
|
||||
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not
|
||||
// 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) ->
|
||||
{
|
||||
ResultAssert.IsSuccess(writer.WriteNull("null"));
|
||||
@@ -198,7 +198,7 @@ public final class RowWriterUnitTests {
|
||||
assert layout.TryFind("tuple<null,tuple<int8,int8>>", tempOut_col5);
|
||||
col = tempOut_col5.get();
|
||||
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,
|
||||
Tuple<NullValue, Tuple<Byte,
|
||||
Byte>> values) ->
|
||||
@@ -240,20 +240,20 @@ public final class RowWriterUnitTests {
|
||||
ResultAssert.IsSuccess(writer.WriteScope(col.path(), col.typeArg().clone(), Tuple.Create(null,
|
||||
(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);
|
||||
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());
|
||||
}
|
||||
|
||||
ResultAssert.IsSuccess(writer2.WriteScope(null, typeArg.getTypeArgs().get(0).clone(), values.Item1,
|
||||
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);
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
@@ -175,7 +175,7 @@ public final class SerializerUnitTest {
|
||||
break;
|
||||
case "resourcePath":
|
||||
Out<String> tempOut_ResourcePath = new Out<String>();
|
||||
r = reader.get().readString(tempOut_ResourcePath);
|
||||
r = reader.get().readUtf8String(tempOut_ResourcePath);
|
||||
retval.ResourcePath = tempOut_ResourcePath.get();
|
||||
if (r != Result.SUCCESS) {
|
||||
return r;
|
||||
|
||||
@@ -17,7 +17,7 @@ public final class AddressSerializer {
|
||||
switch (reader.get().path()) {
|
||||
case "street":
|
||||
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();
|
||||
if (r != Result.SUCCESS) {
|
||||
return r;
|
||||
@@ -26,7 +26,7 @@ public final class AddressSerializer {
|
||||
break;
|
||||
case "city":
|
||||
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();
|
||||
if (r != Result.SUCCESS) {
|
||||
return r;
|
||||
@@ -35,7 +35,7 @@ public final class AddressSerializer {
|
||||
break;
|
||||
case "state":
|
||||
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();
|
||||
if (r != Result.SUCCESS) {
|
||||
return r;
|
||||
|
||||
@@ -60,7 +60,7 @@ public final class PostalCodeSerializer {
|
||||
}
|
||||
|
||||
if (obj.Plus4.HasValue) {
|
||||
r = writer.get().WriteInt16("plus4", obj.Plus4.Value);
|
||||
r = writer.get().writeInt16("plus4", obj.Plus4.Value);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user