mirror of
https://github.com/microsoft/HybridRow.git
synced 2026-01-27 05:13:16 +00:00
Progressed on port from dotnet to java
This commit is contained in:
@@ -14,7 +14,7 @@ import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
|
|||||||
import com.azure.data.cosmos.serialization.hybridrow.RowCursors;
|
import com.azure.data.cosmos.serialization.hybridrow.RowCursors;
|
||||||
import com.azure.data.cosmos.serialization.hybridrow.UnixDateTime;
|
import com.azure.data.cosmos.serialization.hybridrow.UnixDateTime;
|
||||||
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutSpanReadable;
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutSpanReadable;
|
||||||
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutUtf8SpanReadable;
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutUtf8Readable;
|
||||||
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutBinary;
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutBinary;
|
||||||
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutBoolean;
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutBoolean;
|
||||||
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutColumn;
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutColumn;
|
||||||
@@ -1049,7 +1049,7 @@ public final class RowReader {
|
|||||||
LayoutColumn column = this.columns.get(this.columnIndex);
|
LayoutColumn column = this.columns.get(this.columnIndex);
|
||||||
LayoutType type = this.columns.get(this.columnIndex).type();
|
LayoutType type = this.columns.get(this.columnIndex).type();
|
||||||
|
|
||||||
if (!(type instanceof LayoutUtf8SpanReadable)) {
|
if (!(type instanceof LayoutUtf8Readable)) {
|
||||||
value.set(null);
|
value.set(null);
|
||||||
return Result.TYPE_MISMATCH;
|
return Result.TYPE_MISMATCH;
|
||||||
}
|
}
|
||||||
@@ -1059,10 +1059,10 @@ public final class RowReader {
|
|||||||
switch (storage) {
|
switch (storage) {
|
||||||
|
|
||||||
case FIXED:
|
case FIXED:
|
||||||
return type.<LayoutUtf8SpanReadable>typeAs().readFixed(this.row, this.cursor, column, value);
|
return type.<LayoutUtf8Readable>typeAs().readFixed(this.row, this.cursor, column, value);
|
||||||
|
|
||||||
case VARIABLE:
|
case VARIABLE:
|
||||||
return type.<LayoutUtf8SpanReadable>typeAs().readVariable(this.row, this.cursor, column, value);
|
return type.<LayoutUtf8Readable>typeAs().readVariable(this.row, this.cursor, column, value);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
assert false : lenientFormat("expected FIXED or VARIABLE column storage, not %s", storage);
|
assert false : lenientFormat("expected FIXED or VARIABLE column storage, not %s", storage);
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTypedMap;
|
|||||||
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTypes;
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTypes;
|
||||||
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutUDT;
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutUDT;
|
||||||
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutUniqueScope;
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutUniqueScope;
|
||||||
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutUtf8SpanWritable;
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutUtf8Writable;
|
||||||
import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument;
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument;
|
||||||
import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgumentList;
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgumentList;
|
||||||
import com.azure.data.cosmos.serialization.hybridrow.layouts.UpdateOptions;
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.UpdateOptions;
|
||||||
@@ -748,7 +748,7 @@ public final class RowWriter {
|
|||||||
* @param sparse The {@link RowBuffer} access method for <paramref name="type" />.
|
* @param sparse The {@link RowBuffer} access method for <paramref name="type" />.
|
||||||
* @return Success if the write is successful, an error code otherwise.
|
* @return Success if the write is successful, an error code otherwise.
|
||||||
*/
|
*/
|
||||||
private <TLayoutType extends LayoutType<String> & LayoutUtf8SpanWritable> Result writePrimitive(UtfAnyString path, Utf8String value, TLayoutType type, AccessUtf8SpanMethod sparse) {
|
private <TLayoutType extends LayoutType<String> & LayoutUtf8Writable> Result writePrimitive(UtfAnyString path, Utf8String value, TLayoutType type, AccessUtf8SpanMethod sparse) {
|
||||||
Result result = Result.NOT_FOUND;
|
Result result = Result.NOT_FOUND;
|
||||||
if (this.cursor.scopeType() instanceof LayoutUDT) {
|
if (this.cursor.scopeType() instanceof LayoutUDT) {
|
||||||
result = this.writeSchematizedValue(path, value);
|
result = this.writeSchematizedValue(path, value);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import javax.annotation.Nonnull;
|
|||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
public final class LayoutUtf8 extends LayoutTypePrimitive<String> implements LayoutUtf8SpanWritable, LayoutUtf8SpanReadable {
|
public final class LayoutUtf8 extends LayoutTypePrimitive<String> implements LayoutUtf8Readable, LayoutUtf8Writable {
|
||||||
|
|
||||||
public LayoutUtf8() {
|
public LayoutUtf8() {
|
||||||
super(LayoutCode.UTF_8, 0);
|
super(LayoutCode.UTF_8, 0);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import javax.annotation.Nonnull;
|
|||||||
/**
|
/**
|
||||||
* An optional interface that indicates a {@link LayoutType{T}} can also read using a {@link Utf8String}.
|
* An optional interface that indicates a {@link LayoutType{T}} can also read using a {@link Utf8String}.
|
||||||
*/
|
*/
|
||||||
public interface LayoutUtf8SpanReadable extends ILayoutType {
|
public interface LayoutUtf8Readable extends ILayoutType {
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
Result readFixedSpan(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Utf8String> value);
|
Result readFixedSpan(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Utf8String> value);
|
||||||
@@ -13,7 +13,7 @@ import javax.annotation.Nonnull;
|
|||||||
/**
|
/**
|
||||||
* An optional interface that indicates a {@link LayoutType{T}} can also write using a {@link Utf8String}
|
* An optional interface that indicates a {@link LayoutType{T}} can also write using a {@link Utf8String}
|
||||||
*/
|
*/
|
||||||
public interface LayoutUtf8SpanWritable extends ILayoutType {
|
public interface LayoutUtf8Writable extends ILayoutType {
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Utf8String value);
|
Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Utf8String value);
|
||||||
@@ -19,7 +19,7 @@ public class Namespace {
|
|||||||
* Initializes a new instance of the {@link Namespace} class.
|
* Initializes a new instance of the {@link Namespace} class.
|
||||||
*/
|
*/
|
||||||
public Namespace() {
|
public Namespace() {
|
||||||
this.setSchemas(new ArrayList<Schema>());
|
this.schemas(new ArrayList<Schema>());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,28 +37,31 @@ public class Namespace {
|
|||||||
/**
|
/**
|
||||||
* The set of schemas that make up the {@link Namespace}.
|
* The set of schemas that make up the {@link Namespace}.
|
||||||
* <p>
|
* <p>
|
||||||
* Namespaces may consist of zero or more table schemas along with zero or more UDT schemas.
|
* Namespaces may consist of zero or more table schemas along with zero or more UDT schemas. Table schemas can only
|
||||||
* Table schemas can only reference UDT schemas defined in the same namespace. UDT schemas can
|
* reference UDT schemas defined in the same namespace. UDT schemas can contain nested UDTs whose schemas are
|
||||||
* contain nested UDTs whose schemas are defined within the same namespace.
|
* defined within the same namespace.
|
||||||
* @return
|
*
|
||||||
|
* @return list of schemas in the current {@link Namespace}.
|
||||||
*/
|
*/
|
||||||
public final List<Schema> schemas() {
|
public final List<Schema> schemas() {
|
||||||
return this.schemas;
|
return this.schemas;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setSchemas(ArrayList<Schema> value) {
|
public final Namespace schemas(ArrayList<Schema> value) {
|
||||||
this.schemas = value != null ? value : new ArrayList<Schema>();
|
this.schemas = value != null ? value : new ArrayList<Schema>();
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The version of the HybridRow Schema Definition Language used to encode this namespace.
|
* The version of the HybridRow Schema Definition Language used to encode this namespace.
|
||||||
*/
|
*/
|
||||||
public final SchemaLanguageVersion getVersion() {
|
public final SchemaLanguageVersion version() {
|
||||||
return this.version;
|
return this.version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setVersion(SchemaLanguageVersion value) {
|
public final Namespace version(SchemaLanguageVersion value) {
|
||||||
this.version = value;
|
this.version = value;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -3,55 +3,78 @@
|
|||||||
|
|
||||||
package com.azure.data.cosmos.serialization.hybridrow.schemas;
|
package com.azure.data.cosmos.serialization.hybridrow.schemas;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.internal.Murmur3Hash;
|
||||||
|
|
||||||
public final class SchemaHash {
|
public final class SchemaHash {
|
||||||
/** Computes the logical hash for a logical schema.
|
|
||||||
@param ns The namespace within which <paramref name="schema" /> is defined.
|
public static class Code {
|
||||||
@param schema The logical schema to compute the hash of.
|
|
||||||
@param seed The seed to initialized the hash function.
|
private final long low;
|
||||||
@return The logical 128-bit hash as a two-tuple (low, high).
|
private final long high;
|
||||||
|
|
||||||
|
private Code(long low, long high) {
|
||||||
|
this.low = low;
|
||||||
|
this.high = high;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long high() {
|
||||||
|
return this.high;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long low() {
|
||||||
|
return this.low;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes the logical hash for a logical schema.
|
||||||
|
* @param ns The namespace within which <paramref name="schema" /> is defined.
|
||||||
|
* @param schema The logical schema to compute the hash of.
|
||||||
|
* @param seed The seed to initialized the hash function.
|
||||||
|
* @return The logical 128-bit hash as a two-tuple (low, high).
|
||||||
*/
|
*/
|
||||||
// TODO: C# TO JAVA CONVERTER: Methods returning tuples are not converted by C# to Java Converter:
|
public static Code ComputeHash(Namespace ns, Schema schema, Code seed)
|
||||||
// public static(ulong low, ulong high) ComputeHash(Namespace ns, Schema schema, (ulong low, ulong high) seed =
|
{
|
||||||
// default)
|
Code hash = seed;
|
||||||
// {
|
|
||||||
// (ulong low, ulong high) hash = seed;
|
hash = Murmur3Hash.Hash128(schema.schemaId(), hash);
|
||||||
// hash = Murmur3Hash.Hash128(schema.SchemaId, hash);
|
hash = Murmur3Hash.Hash128(schema.type(), hash);
|
||||||
// hash = Murmur3Hash.Hash128(schema.Type, hash);
|
hash = SchemaHash.ComputeHash(ns, schema.options(), hash);
|
||||||
// hash = SchemaHash.ComputeHash(ns, schema.Options, hash);
|
|
||||||
// if (schema.PartitionKeys != null)
|
if (schema.partitionKeys() != null)
|
||||||
// {
|
{
|
||||||
// foreach (PartitionKey p in schema.PartitionKeys)
|
foreach (PartitionKey p in schema.PartitionKeys)
|
||||||
// {
|
{
|
||||||
// hash = SchemaHash.ComputeHash(ns, p, hash);
|
hash = SchemaHash.ComputeHash(ns, p, hash);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// if (schema.PrimarySortKeys != null)
|
if (schema.PrimarySortKeys != null)
|
||||||
// {
|
{
|
||||||
// foreach (PrimarySortKey p in schema.PrimarySortKeys)
|
foreach (PrimarySortKey p in schema.PrimarySortKeys)
|
||||||
// {
|
{
|
||||||
// hash = SchemaHash.ComputeHash(ns, p, hash);
|
hash = SchemaHash.ComputeHash(ns, p, hash);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// if (schema.StaticKeys != null)
|
if (schema.StaticKeys != null)
|
||||||
// {
|
{
|
||||||
// foreach (StaticKey p in schema.StaticKeys)
|
foreach (StaticKey p in schema.StaticKeys)
|
||||||
// {
|
{
|
||||||
// hash = SchemaHash.ComputeHash(ns, p, hash);
|
hash = SchemaHash.ComputeHash(ns, p, hash);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// if (schema.Properties != null)
|
if (schema.Properties != null)
|
||||||
// {
|
{
|
||||||
// foreach (Property p in schema.Properties)
|
foreach (Property p in schema.Properties)
|
||||||
// {
|
{
|
||||||
// hash = SchemaHash.ComputeHash(ns, p, hash);
|
hash = SchemaHash.ComputeHash(ns, p, hash);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// return hash;
|
return hash;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// TODO: C# TO JAVA CONVERTER: Methods returning tuples are not converted by C# to Java Converter:
|
// TODO: C# TO JAVA CONVERTER: Methods returning tuples are not converted by C# to Java Converter:
|
||||||
// private static(ulong low, ulong high) ComputeHash(Namespace ns, SchemaOptions options, (ulong low, ulong high)
|
// private static(ulong low, ulong high) ComputeHash(Namespace ns, SchemaOptions options, (ulong low, ulong high)
|
||||||
|
|||||||
@@ -3,6 +3,9 @@
|
|||||||
|
|
||||||
package com.azure.data.cosmos.serialization.hybridrow.schemas;
|
package com.azure.data.cosmos.serialization.hybridrow.schemas;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Describes the sort order direction.
|
* Describes the sort order direction.
|
||||||
*/
|
*/
|
||||||
@@ -10,15 +13,16 @@ public enum SortDirection {
|
|||||||
/**
|
/**
|
||||||
* Sorts from the lowest to the highest value.
|
* Sorts from the lowest to the highest value.
|
||||||
*/
|
*/
|
||||||
Ascending(0),
|
ASCENDING(0),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sorts from the highests to the lowest value.
|
* Sorts from the highests to the lowest value.
|
||||||
*/
|
*/
|
||||||
Descending(1);
|
DESCENDING(1);
|
||||||
|
|
||||||
public static final int SIZE = java.lang.Integer.SIZE;
|
public static final int BYTEST = Integer.BYTES;
|
||||||
private static java.util.HashMap<Integer, SortDirection> mappings;
|
|
||||||
|
private static Int2ObjectMap<SortDirection> mappings;
|
||||||
private int value;
|
private int value;
|
||||||
|
|
||||||
SortDirection(int value) {
|
SortDirection(int value) {
|
||||||
@@ -30,15 +34,15 @@ public enum SortDirection {
|
|||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SortDirection forValue(int value) {
|
public static SortDirection from(int value) {
|
||||||
return mappings().get(value);
|
return mappings().get(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static java.util.HashMap<Integer, SortDirection> mappings() {
|
private static Int2ObjectMap<SortDirection> mappings() {
|
||||||
if (mappings == null) {
|
if (mappings == null) {
|
||||||
synchronized (SortDirection.class) {
|
synchronized (SortDirection.class) {
|
||||||
if (mappings == null) {
|
if (mappings == null) {
|
||||||
mappings = new java.util.HashMap<>();
|
mappings = new Int2ObjectOpenHashMap<>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -688,8 +688,8 @@ class AnonymousType3 {
|
|||||||
|
|
||||||
pulic String Path
|
pulic String Path
|
||||||
pubblct[] expectedSchemas = new Object[] { AnonymousType("{'path': 'a'}", "{'path': 'b', 'direction': 'desc'}, " +
|
pubblct[] expectedSchemas = new Object[] { AnonymousType("{'path': 'a'}", "{'path': 'b', 'direction': 'desc'}, " +
|
||||||
"{'path': 'c'}", new String[] { "a" }, new Object[] { AnonymousType2("b", SortDirection.Descending),
|
"{'path': 'c'}", new String[] { "a" }, new Object[] { AnonymousType2("b", SortDirection.DESCENDING),
|
||||||
AnonymousType3("c", SortDirection.Ascending) }) };
|
AnonymousType3("c", SortDirection.ASCENDING) }) };
|
||||||
|
|
||||||
for(bjeic AnonymousType3(String _Path, SortDirection _Dir) {
|
for(bjeic AnonymousType3(String _Path, SortDirection _Dir) {
|
||||||
Path = _Path;
|
Path = _Path;
|
||||||
|
|||||||
Reference in New Issue
Block a user