Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions table/src/main/java/tech/ydb/table/impl/DataQueryImpl.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package tech.ydb.table.impl;

import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -14,7 +13,6 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.common.hash.Hashing;

import tech.ydb.core.Result;
import tech.ydb.proto.ValueProtos;
Expand All @@ -27,8 +25,6 @@
import tech.ydb.table.values.Value;
import tech.ydb.table.values.proto.ProtoType;

import static com.google.common.base.Preconditions.checkArgument;


/**
* @author Sergey Polovko
Expand All @@ -41,7 +37,6 @@ final class DataQueryImpl implements DataQuery {
private final ImmutableMap<String, ValueProtos.Type> typesPb;
@Nullable
private final String text;
private final String textHash;

DataQueryImpl(
BaseSession session,
Expand All @@ -54,13 +49,6 @@ final class DataQueryImpl implements DataQuery {
this.types = buildTypes(parametersTypes);
this.typesPb = ImmutableMap.copyOf(parametersTypes);
this.text = keepText ? text : null;
this.textHash = makeHash(text);
}

static String makeHash(String text) {
return Hashing.sha256()
.hashString(text, StandardCharsets.UTF_8)
.toString();
}

private static ImmutableMap<String, Type> buildTypes(Map<String, ValueProtos.Type> parametersTypes) {
Expand Down Expand Up @@ -91,10 +79,6 @@ public Optional<String> getText() {
return Optional.ofNullable(text);
}

String getTextHash() {
return textHash;
}

@Override
public CompletableFuture<Result<DataQueryResult>> execute(
TxControl<?> txControl, Params params, ExecuteDataQuerySettings settings) {
Expand All @@ -108,6 +92,7 @@ public CompletableFuture<Result<DataQueryResult>> execute(
*/
@ParametersAreNonnullByDefault
static final class DataQueryParams implements Params {
private static final long serialVersionUID = -7431562469459950668L;
private final ImmutableMap<String, Type> types;
private final ImmutableMap<String, ValueProtos.Type> typesPb;
private final HashMap<String, Value<?>> params;
Expand All @@ -126,7 +111,7 @@ public boolean isEmpty() {
@Override
public <T extends Type> Params put(String name, Value<T> value) {
Type type = types.get(name);
checkArgument(type != null, "unknown parameter: %s", name);
Preconditions.checkArgument(type != null, "unknown parameter: %s", name);

//TODO: This check will not work with Decimal type
//checkArgument(type.equals(value.getType()), "types mismatch: expected %s, got %s", type, value.getType());
Expand Down
3 changes: 2 additions & 1 deletion table/src/main/java/tech/ydb/table/query/Params.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tech.ydb.table.query;

import java.io.Serializable;
import java.util.Map;

import javax.annotation.ParametersAreNonnullByDefault;
Expand All @@ -13,7 +14,7 @@
* @author Sergey Polovko
*/
@ParametersAreNonnullByDefault
public interface Params {
public interface Params extends Serializable {

/**
* Returns an immutable implementation of {@link Params} with no parameters.
Expand Down
39 changes: 20 additions & 19 deletions table/src/main/java/tech/ydb/table/query/ParamsImmutableMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@

import javax.annotation.ParametersAreNonnullByDefault;

import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;

import tech.ydb.proto.ValueProtos.TypedValue;
import tech.ydb.table.values.Type;
import tech.ydb.table.values.Value;

import static com.google.common.base.Preconditions.checkArgument;
import static tech.ydb.table.values.proto.ProtoValue.toTypedValue;
import tech.ydb.table.values.proto.ProtoValue;


/**
Expand All @@ -23,25 +22,27 @@
*/
@ParametersAreNonnullByDefault
final class ParamsImmutableMap implements Params {
static final ParamsImmutableMap EMPTY = new ParamsImmutableMap(new HashMap<>());
private static final long serialVersionUID = -4446062098045167272L;

static final ParamsImmutableMap EMPTY = new ParamsImmutableMap(Collections.emptyMap());

private final Map<String, Value<?>> params;
private final HashMap<String, Value<?>> params;

private ParamsImmutableMap(Map<String, Value<?>> params) {
private ParamsImmutableMap(HashMap<String, Value<?>> params) {
this.params = params;
}

static ParamsImmutableMap create(String name, Value<?> value) {
return new ParamsImmutableMap(Collections.singletonMap(name, value));
HashMap<String, Value<?>> params = Maps.newHashMapWithExpectedSize(1);
params.put(name, value);
return new ParamsImmutableMap(params);
}

static ParamsImmutableMap create(String name1, Value<?> value1, String name2, Value<?> value2) {
checkArgument(!name1.equals(name2), "parameter duplicate: %s", name1);
Preconditions.checkArgument(!name1.equals(name2), "parameter duplicate: %s", name1);
HashMap<String, Value<?>> params = Maps.newHashMapWithExpectedSize(2);
params.put(name1, value1);
params.put(name2, value2);
return new ParamsImmutableMap(Collections.unmodifiableMap(params));
return new ParamsImmutableMap(params);
}

static ParamsImmutableMap create(
Expand All @@ -52,7 +53,7 @@ static ParamsImmutableMap create(
params.put(name1, value1);
putParam(params, name2, value2);
putParam(params, name3, value3);
return new ParamsImmutableMap(Collections.unmodifiableMap(params));
return new ParamsImmutableMap(params);
}

@SuppressWarnings("checkstyle:ParameterNumber")
Expand All @@ -66,7 +67,7 @@ static ParamsImmutableMap create(
putParam(params, name2, value2);
putParam(params, name3, value3);
putParam(params, name4, value4);
return new ParamsImmutableMap(Collections.unmodifiableMap(params));
return new ParamsImmutableMap(params);
}

@SuppressWarnings("checkstyle:ParameterNumber")
Expand All @@ -82,7 +83,7 @@ static ParamsImmutableMap create(
putParam(params, name3, value3);
putParam(params, name4, value4);
putParam(params, name5, value5);
return new ParamsImmutableMap(Collections.unmodifiableMap(params));
return new ParamsImmutableMap(params);
}

@SuppressWarnings("checkstyle:ParameterNumber")
Expand All @@ -100,7 +101,7 @@ static ParamsImmutableMap create(
putParam(params, name4, value4);
putParam(params, name5, value5);
putParam(params, name6, value6);
return new ParamsImmutableMap(Collections.unmodifiableMap(params));
return new ParamsImmutableMap(params);
}

@SuppressWarnings("checkstyle:ParameterNumber")
Expand All @@ -120,7 +121,7 @@ static ParamsImmutableMap create(
putParam(params, name5, value5);
putParam(params, name6, value6);
putParam(params, name7, value7);
return new ParamsImmutableMap(Collections.unmodifiableMap(params));
return new ParamsImmutableMap(params);
}

@SuppressWarnings("checkstyle:ParameterNumber")
Expand All @@ -142,7 +143,7 @@ static ParamsImmutableMap create(
putParam(params, name6, value6);
putParam(params, name7, value7);
putParam(params, name8, value8);
return new ParamsImmutableMap(Collections.unmodifiableMap(params));
return new ParamsImmutableMap(params);
}

@SuppressWarnings("checkstyle:ParameterNumber")
Expand All @@ -166,11 +167,11 @@ static ParamsImmutableMap create(
putParam(params, name7, value7);
putParam(params, name8, value8);
putParam(params, name9, value9);
return new ParamsImmutableMap(Collections.unmodifiableMap(params));
return new ParamsImmutableMap(params);
}

private static void putParam(HashMap<String, Value<?>> params, String name, Value<?> value) {
checkArgument(params.putIfAbsent(name, value) == null, "parameter duplicate: %s", name);
Preconditions.checkArgument(params.putIfAbsent(name, value) == null, "parameter duplicate: %s", name);
}

@Override
Expand All @@ -187,7 +188,7 @@ public <T extends Type> Params put(String name, Value<T> value) {
public Map<String, TypedValue> toPb() {
Map<String, TypedValue> result = Maps.newHashMapWithExpectedSize(params.size());
for (Map.Entry<String, Value<?>> entry : params.entrySet()) {
result.put(entry.getKey(), toTypedValue(entry.getValue()));
result.put(entry.getKey(), ProtoValue.toTypedValue(entry.getValue()));
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/
@ParametersAreNonnullByDefault
final class ParamsMutableMap implements Params {
private static final long serialVersionUID = -2195403246008082524L;

private final HashMap<String, Value<?>> params;

Expand Down
8 changes: 6 additions & 2 deletions table/src/main/java/tech/ydb/table/values/DecimalType.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tech.ydb.table.values;

import java.io.Serializable;
import java.math.BigDecimal;
import java.math.BigInteger;

Expand All @@ -13,12 +14,13 @@
* @author Sergey Polovko
*/
public class DecimalType implements Type {

public static final int MAX_PRECISION = 35;

private static final InfValues[] INF_VALUES;
private static final DecimalType YDB_DEFAULT;

private static final long serialVersionUID = 5260350619058403189L;

static {
// Precalculate +inf/-inf values for all precisions
INF_VALUES = new InfValues[DecimalType.MAX_PRECISION];
Expand Down Expand Up @@ -171,7 +173,9 @@ boolean isNegInf(long high, long low) {
return high < inf.negHigh || (high == inf.negHigh && Long.compareUnsigned(low, inf.negLow) <= 0);
}

private static class InfValues {
private static class InfValues implements Serializable {
private static final long serialVersionUID = 3291796497109728849L;

private final long posHigh;
private final long posLow;
private final long negHigh;
Expand Down
2 changes: 2 additions & 0 deletions table/src/main/java/tech/ydb/table/values/DecimalValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public class DecimalValue implements Value<DecimalType> {
public static final DecimalValue NAN = new DecimalValue(
MAX_DECIMAL, 0x0013426172C74D82L, 0x2B878FE800000001L);

private static final long serialVersionUID = 1362798151263983188L;

private final DecimalType type;
private final long high;
private final long low;
Expand Down
6 changes: 3 additions & 3 deletions table/src/main/java/tech/ydb/table/values/DictType.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package tech.ydb.table.values;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -12,6 +11,7 @@
* @author Sergey Polovko
*/
public final class DictType implements Type {
private static final long serialVersionUID = -2863510622617082427L;

private final Type keyType;
private final Type valueType;
Expand Down Expand Up @@ -71,7 +71,7 @@ public ValueProtos.Type toPb() {
}

public DictValue emptyValue() {
return new DictValue(this, Collections.emptyMap());
return new DictValue(this, new HashMap<>());
}

public DictValue newValueCopy(Map<Value<?>, Value<?>> items) {
Expand All @@ -85,6 +85,6 @@ public DictValue newValueOwn(Map<Value<?>, Value<?>> items) {
if (items.isEmpty()) {
return emptyValue();
}
return new DictValue(this, items);
return new DictValue(this, new HashMap<>(items));
}
}
13 changes: 7 additions & 6 deletions table/src/main/java/tech/ydb/table/values/DictValue.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tech.ydb.table.values;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

Expand All @@ -15,19 +15,20 @@
* @author Sergey Polovko
*/
public class DictValue implements Value<DictType> {
private static final long serialVersionUID = 6205349432501922070L;

private final DictType type;
private final Map<Value<?>, Value<?>> items;
private final HashMap<Value<?>, Value<?>> items;

DictValue(DictType type, Map<Value<?>, Value<?>> items) {
DictValue(DictType type, HashMap<Value<?>, Value<?>> items) {
this.type = type;
this.items = items;
}

public static DictValue of(Value<?> key, Value<?> value) {
return new DictValue(
DictType.of(key.getType(), value.getType()),
Collections.singletonMap(key, value));
HashMap<Value<?>, Value<?>> map = new HashMap<>();
map.put(key, value);
return new DictValue(DictType.of(key.getType(), value.getType()), map);
}

public int size() {
Expand Down
1 change: 1 addition & 0 deletions table/src/main/java/tech/ydb/table/values/ListType.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* @author Sergey Polovko
*/
public final class ListType implements Type {
private static final long serialVersionUID = -2673063704709926669L;

private final Type itemType;

Expand Down
1 change: 1 addition & 0 deletions table/src/main/java/tech/ydb/table/values/ListValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* @author Sergey Polovko
*/
public class ListValue implements Value<ListType> {
private static final long serialVersionUID = 8672625561012902978L;

private final ListType type;
private final Value<?>[] items;
Expand Down
2 changes: 1 addition & 1 deletion table/src/main/java/tech/ydb/table/values/NullType.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
* @author Aleksandr Gorshenin
*/
public final class NullType implements Type {

private static final NullType INSTANCE = new NullType();
private static final long serialVersionUID = 5283267584194481781L;

private NullType() {
}
Expand Down
2 changes: 1 addition & 1 deletion table/src/main/java/tech/ydb/table/values/NullValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
* @author Aleksandr Gorshenin
*/
public class NullValue implements Value<NullType> {

private static final NullValue INSTANCE = new NullValue();
private static final long serialVersionUID = 7394540932620428882L;

private NullValue() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* @author Sergey Polovko
*/
public final class OptionalType implements Type {
private static final long serialVersionUID = 9055043063372724062L;

private final Type itemType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
@ParametersAreNonnullByDefault
public class OptionalValue implements Value<OptionalType> {
private static final long serialVersionUID = -6012287716342869258L;

private final OptionalType type;
@Nullable
Expand Down
1 change: 1 addition & 0 deletions table/src/main/java/tech/ydb/table/values/PgType.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* @author Aleksandr Gorshenin
*/
public class PgType implements Type {
private static final long serialVersionUID = -645693159447347308L;
private final int oid;
private final int typlen;
private final int typmod;
Expand Down
Loading